# Extract part of a filename

**URL:** <https://community.glideapps.com/t/extract-part-of-a-filename/81827>\
**Category:** Ask for Help\
**Created:** [May 11, 2025, 5:12pm UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827 "2025-05-11T17:12:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Korbib](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/korbib/32/71813_2.png) [@Korbib](https://community.glideapps.com/u/Korbib)\
**Post date:** [May 11, 2025, 5:12pm UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827/1 "2025-05-11T17:12:58Z")

</div>

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 🙏

---

<div class="post-metadata">

**Author:** ![HTML](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/html/32/87893_2.png) [@HTML](https://community.glideapps.com/u/HTML)\
**Post date:** [May 11, 2025, 5:39pm UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827/2 "2025-05-11T17:39:31Z")

</div>

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

```auto
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'}

```

---

<div class="post-metadata">

**Author:** ![Korbib](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/korbib/32/71813_2.png) [@Korbib](https://community.glideapps.com/u/Korbib)\
**Post date:** [May 11, 2025, 6:12pm UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827/3 "2025-05-11T18:12:32Z")

</div>

Thank you 🙏

It works 🥳

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [May 11, 2025, 11:42pm UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827/4 "2025-05-11T23:42:29Z")

</div>

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

 ![CleanShot 2025-05-12 at 06.40.16@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/0/a0c284b4974c83fde41c73d879c950e3ba64a473.png)

If you want the leading 0.

```auto
_V(\d+)

```

 ![CleanShot 2025-05-12 at 06.41.51@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/0/20e8b1263bc0a08ffda1d6774a13441e65cb6609.png)

This if you don’t want the leading 0.

```auto
_V(?:0(?=[1-9]))?(\d+)

```

---

<div class="post-metadata">

**Author:** ![HTML](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/html/32/87893_2.png) [@HTML](https://community.glideapps.com/u/HTML)\
**Post date:** [May 11, 2025, 11:52pm UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827/5 "2025-05-11T23:52:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Korbib](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/korbib/32/71813_2.png) [@Korbib](https://community.glideapps.com/u/Korbib)\
**Post date:** [May 12, 2025, 7:40am UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827/6 "2025-05-12T07:40:02Z")

</div>

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

Thank you so much 🙏

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [May 19, 2025, 7:40am UTC](https://community.glideapps.com/t/extract-part-of-a-filename/81827/7 "2025-05-19T07:40:04Z")

</div>

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