How to replace back slash in CTL2

Hi,

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

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?

Thanks.

Hi Mukunku,
try changing your code to the following:

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

The reason why 4 backslashes are needed to reference one is that there are 2 levels of interpretation:

  • At first, CloverETL interprets the “\\\\” string as 2 backslashes (each one escaped by a backslash).

  • 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,