Extract part of a filename

Hello there,

I have a several files with filenames like :
myfirstsong-CT_V06.mp3
mysecondsong-CT_V04.mp3
mythirdsong-CT_V11.mp3

which the number is the version of the song and I need to extract this number to be displayed in my app without manually typing it in the data editor.

Is there a way to do it ?

Thanks :folded_hands:

You can use JavaScript column, paste this code there, and in p1 put your file name:

if(p1){
const match = p1.match(/_V(\d+)/);
if (match) {
  const numberAfterV = match[1];
  return(Number(numberAfterV));
} else {
  return("No number found");
}
} else {return 'empty'}
1 Like

Thank you :folded_hands:

It works :partying_face:

1 Like

You can also use the Extract Matching Text column for this.

If you want the leading 0.

_V(\d+)

This if you don’t want the leading 0.

_V(?:0(?=[1-9]))?(\d+)
2 Likes

Yes, you can do that, but you won’t have control over errors, empty values, or missing numbers in the name. You’d need to add additional columns to handle those cases.

1 Like

Ho yes ! That works too and it doesn’t need an if-then-else to filter the results :blush:

Thank you so much :folded_hands:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.