How to replace back slash in CTL2

Support/help with CloverETL implementation problems

Posts: 5
Joined: Wed Nov 01, 2017 3:49 pm

How to replace back slash in CTL2

Postby mukunku » Tue Feb 13, 2018 4:29 pm


I want to replace all back slashes with forward slashes and I have the following statement in my CTL2 code:

Code: Select all

replace(myString, "\\", "/");

But I get this error:
Invalid regular expression: "\"

So the interpreter thinks this is a regular expression when in fact it's a string literal. Any way to work around this?


Posts: 63
Joined: Wed May 03, 2017 12:10 pm

Re: How to replace back slash in CTL2

Postby bartonv » Tue Feb 20, 2018 10:36 am

Hi Mukunku,
try changing your code to the following:

Code: Select all

replace(myString, "\\\\", "/");

The reason why 4 backslashes are needed to reference one is that there are 2 levels of interpretation:
  1. At first, CloverETL interprets the “\\\\” string as 2 backslashes (each one escaped by a backslash).
  2. Then, the “\\” string is pushed to the ‘replace’ function as a regular expression. Note: the ‘replace’ function accepts regex expressions only as their second argument, more information can be found in our documentation). Similarly, “\\” is interpreted as “\” in regex (the backslash needs to be escaped by a backslash). More information can be found here.
Kind regards,
Vladimir Barton
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at
How to speed up communication with CloverCARE support