4

I'm having dificulty extracting the filename from another cell. The regular expression I have works perfectly on regex101.com but only results in error on airtable.

My working regular expression has a non capturing group followed by everything else:- (?:[\\])(.*)

An example string I'm working with is Tech Stuff - Old Channels - image-assets [839605635295772672].csv_Files\IMG_0165-E23DF.JPG

Does airtable support regular expression groups and if so, what am I doing wrong.

My airtable formulae reads REGEX_EXTRACT( {Attachments}, '(?:[\\])(.*)') but results in error however REGEX_EXTRACT( {Attachments}, '[A-Za-z]*.[A-Za-z]*') gets me 'Tech Stuff' no problem but if I try REGEX_EXTRACT( {Attachments}, '(?>[A-Za-z]*)(.[A-Za-z]*)') I just get #ERROR

spaceshipdev
  • 101
  • 1
  • 10

1 Answers1

2

You may try:

REGEX_EXTRACT({Attachments}, '[^\\\\]+\\.[^.]+$')

The regex pattern here says to match:

[^\\]+  a group on non backslash characters
\.      dot
[^.]+   the file extension

Demo

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Thanks, wow this is SO close. I have the file extension excluding the . so `png` `JPG` Funny though, because in Regex101.com it does indeed match the whole filename exclusivly. – spaceshipdev Jan 07 '22 at 03:01
  • This works in Regex101 but not in airtable. `REGEX_EXTRACT({Attachments}, '[^\\]+\.[^.]+$')` only gets me the file extension and not the full filename including extension. – spaceshipdev Jan 07 '22 at 03:13
  • It isn't possible for my pattern to just give you the extension. Based on your input above (and from my demo), can you let me know exactly what this current pattern is matching? – Tim Biegeleisen Jan 07 '22 at 03:16
  • Matches `JPG` only – spaceshipdev Jan 07 '22 at 03:18
  • 1
    Please try this pattern: `[^\\\\]+\\.[^.]+$` ... or maybe `[^\\]+\\.[^.]+$` ... I think the issue here might be that backslash needs to be doubled everywhere – Tim Biegeleisen Jan 07 '22 at 03:24
  • Yes, you are correct; they do. This works `[^\\\\]+\\.[^.]+$` thanks so much! If I type a single slash in airtable, it always seems to auto escape it automatically, rather annoying but yes, this was the issue. – spaceshipdev Jan 07 '22 at 03:27