Skip to main content
Solved

Formula to ignore everything LEFT of last "/" in file path and file name

  • May 26, 2021
  • 3 replies
  • 35 views

Forum|alt.badge.img+7

Hi there,

I have a conundrum that I hope someone can please help me with! It’s all about the final “/”

Basically I want to extract the last part of a file path + filename string, to leave only the filename. The path and name can all be different lengths, and have different folder depths. The key is to take everything AFTER the final “/” Examples below…

/Volumes/my_drive/documents/pictures/A001.jpeg
/mnt/usb/pictures/123456.tiff
/Server/over_there/no_really/this_one/what a long path/Big File.mov

would parse…

A001.jpeg
123456.tiff
Big File.mov

Any ideas please, fantastic Airtable community?

Thanks!

Best answer by Kamille_Parks11

You could do it with REGEX_REPLACE()

REGEX_REPLACE(
   {Field Name}, 
   "^(.+)\\/([^\\/]+)$", 
   "$2"
)

3 replies

Kamille_Parks11
Forum|alt.badge.img+27
  • Brainy
  • 2679 replies
  • Answer
  • May 26, 2021

You could do it with REGEX_REPLACE()

REGEX_REPLACE(
   {Field Name}, 
   "^(.+)\\/([^\\/]+)$", 
   "$2"
)

Forum|alt.badge.img+7
  • Author
  • Known Participant
  • 11 replies
  • May 26, 2021

You could do it with REGEX_REPLACE()

REGEX_REPLACE(
   {Field Name}, 
   "^(.+)\\/([^\\/]+)$", 
   "$2"
)

That’s amazing Kamille, thanks so much! Worked a charm, you got the skills! Appreciate it.
Cheers.


Forum|alt.badge.img+5
  • Participating Frequently
  • 6 replies
  • March 28, 2023

This is really a helpful solution!

I'm still stuck with another related issue. I need to extract the string from the second-to-last section of a file path, essentially to isolate the parent folder of a file or folder. I've looked into regular expressions and have found them to be a bit daunting, so I can't build upon this solution here. 

Using EastEndTom's sample, I need to extract "pictures"  from /Volumes/my_drive/documents/pictures/A001.jpeg.

Does anyone have any suggestions for me?

Thanks!