I’m stuck trying to get a filename from another cell in Airtable. My regex works fine on regex101.com but Airtable keeps giving me errors.
Here’s what I’m trying to do:
REGEX_EXTRACT({Attachments}, '(?:[\\])(.*)')
It’s supposed to grab everything after the last backslash. For example, from this:
Tech Stuff - Old Channels 💀 - image-assets [839605635295772672].csv_Files\IMG_0165-E23DF.JPG
I want to get IMG_0165-E23DF.JPG
.
Simple stuff like [A-Za-z]*.[A-Za-z]*
works and gives me ‘Tech Stuff’, but anything with groups or more complex patterns just throws an error.
Does Airtable handle regex groups differently? What am I missing here? Any tips would be great!
hey elizabeths, airtable’s regex is kinda funky. try this instead:
REGEX_EXTRACT({Attachments}, ‘[^\/]+$’)
it looks for chars that aren’t slashes at the end. should grab ur filename without the group mess. lmk if it works!
I’ve encountered similar issues with Airtable’s regex implementation. It’s quite restrictive compared to standard regex engines. One approach that’s worked well for me is using a combination of REGEX_EXTRACT and SPLIT:
LAST(SPLIT({Attachments}, ‘\’))
This formula splits the string at each backslash and then selects the last element, which should be your filename. It’s more robust than complex regex patterns in Airtable and handles various file path formats well.
If you’re dealing with forward slashes instead, just replace ‘\’ with ‘/’. This method has been reliable in my projects, especially when dealing with inconsistent file path structures.
I’ve had similar struggles with Airtable’s regex implementation. It’s quite limited compared to full-fledged regex engines. One workaround I’ve found effective is using a combination of REGEX_EXTRACT and string manipulation functions.
Try this formula:
RIGHT({Attachments}, LEN({Attachments}) - FIND(REGEX_EXTRACT({Attachments}, ‘\’), {Attachments}))
This approach first finds the position of the last backslash using REGEX_EXTRACT, then uses RIGHT to extract everything after that position. It’s not as elegant as a single regex, but it’s reliable in Airtable’s environment.
If you’re dealing with different file path formats, you might need to adjust the delimiter in the REGEX_EXTRACT part. Hope this helps!