String Manipulation - regexReplace with variable

Hi,

when I use the String manipulation with the following code to replace from the field Text all the hits of the regex with  "aaa123" it works fine:

regexReplace($Text$, "MAL?[\\p{L}\\p{N}]*(\\s|$|\\p{P}|\\{Sc})", "aaa123")

 

 

But if I insert the same Regex    MAL?[\\p{L}\\p{N}]*(\\s|$|\\p{P}|\\{Sc})     in a cell or a variable called MyRegex and I write the following code it does not work and I get as a result a null "?":

regexReplace($Text$, $MyRegex$, "aaa123")

 

This problem does not appen if the regex does not contain the curly brackets {}

 

How is it possible? How can I solve it?

Thanks in advance

Regards

 

 

 

 

1 Like

I doubt you can refer to variables with the $MyRegex$ syntax. I would try something like $${SMyRegex}$$ instead.

Thank you, Aborg. 

With $MyRegex$ I was referring to a field name... I also tried with the creation of a variable and the use of $${SMyRegex}$$ but it didn't work beacuse this is not the problem.

The problem is that if the regex contains curly brackets and it is inserted in a variable the following code doesn't work:

regexReplace($Text$, $$MyRegex$$, "aaa123")

 

If the regex doesn't not contain any curly brackets then it works.

How could I solve this problem?

Thanks

 

P.S. I also tried adding \ before the curly brackets. This avoid to ge a null ? as a result but nothing is replaced because there are no matches with this regex...

 

P.S.2 In my prevoius message there is a typing error from my side. The regex is not  MAL?[\\p{L}\\p{N}]*(\\s|$|\\p{P}|\\{Sc})      but it is    MAL?[\\p{L}\\p{N}]*(\\s|$|\\p{P}|\\p{Sc})