# Guidance on regexReplace function

**URL:** <https://forum.knime.com/t/guidance-on-regexreplace-function/21734>\
**Category:** KNIME Analytics Platform\
**Created:** [March 12, 2020, 3:58pm UTC](https://forum.knime.com/t/guidance-on-regexreplace-function/21734 "2020-03-12T15:58:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Jeff](https://forum.knime.com/u/Jeff)\
**Post date:** [March 12, 2020, 3:58pm UTC](https://forum.knime.com/t/guidance-on-regexreplace-function/21734/1 "2020-03-12T15:58:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [March 12, 2020, 4:30pm UTC](https://forum.knime.com/t/guidance-on-regexreplace-function/21734/2 "2020-03-12T16:30:12Z")

</div>

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](https://stackoverflow.com/questions/4025482/cant-escape-the-backslash-with-regex).

Also you can use following syntax in [String Manipulation](https://kni.me/n/eOn8ibZnxIkY7XhT) 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

---

<div class="post-metadata">

**Author:** ![Jeff](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@Jeff](https://forum.knime.com/u/Jeff)\
**Post date:** [March 12, 2020, 4:34pm UTC](https://forum.knime.com/t/guidance-on-regexreplace-function/21734/3 "2020-03-12T16:34:44Z")

</div>

Awesome… thanks I’ll try it out!

Jeff

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [March 19, 2020, 4:34pm UTC](https://forum.knime.com/t/guidance-on-regexreplace-function/21734/4 "2020-03-19T16:34:49Z")

</div>

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