Guidance on regexReplace function

Hi,

I’m struggling to some syntax right and perhaps someone might help.

From the “List Files” node I get set of rows containing file name and a URL of files in a directory. Say the file location rows like the following:
c:\MyDir\Dir1\Save\f1.txt
c:\MyDir\Dir2\Save\f2.txt
c:\MyDir\Dir3\Save\f3.txt

using regexReplace I’m trying to replace the string prior to file name so rows would look like:
f1.txt
f2.txt
f3.txt

I have in expression editor the following…
RegexReplace(column(“Location”), “c:\MyDir\(Dir1|Dir2|Dir3)\Save\”,"") Added note: previous has double blackslashes in the 4 locations it only shows one. It gives me an error on closing about unmatched “)”. Maybe someone with more regex experience might be able to give me a bit of guidance on the above to correct. Can’t I use match multiple strings?

Thanks for your insight.
Jeff

Hi there @Jeff,

to escape backslash character in regex function you need 4 backslashes! So something like this should work:

regexReplace($column1$,"c:\\\\MyDir\\\\(Dir1|Dir2|Dir3)\\\\Save\\\\","")

More about that here.

Also you can use following syntax in String Manipulation node to obtain file name together with extension:

substr($column1$,indexOf($column1$,"\\","b") + 1)

Basically it says get me everything after last backslash.

Hope this helps!

Br,
Ivan

6 Likes

Awesome… thanks I’ll try it out!

Jeff

1 Like

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