String Replace: RegEx requires double escape

Hi,

when using this RegEx \d(?:[.,0-9/-\s]+)?[\w]+\s? this error is thrown Invalid node settings: Coding issue: Illegal character range near index 14.

I figured that, after counting to the failing position, a double escape might be required which seems counter intuitive or at least inconsistent: \d(?:[.,0-9/-\\s]+)?[\w]+\s?

I’d like to suggest to either fix the cause or improve the error message but depending on the RegEx implementation, the later might cause more work considering other edge cases.

PS: This RegEx does work without double escaping (^|[^\d])\.

Best
MIke

The problem lies in the regex, not in the node’s behaviour. The - in your regex indicates a character range such as a-z. However, a character range /-\s doesn’t make sense because \s stands for multiple characters. If you simply want to match a - then you have to escape the -: [.,0-9/\-\s]
The reason why it works with \\s is that you now have a character range /-\ plus a single s character.

3 Likes

Hi @mwiegand, @thor
I think I have a similar issue when trying to remove multiline-comments in java/javascript code snippets with \\/\\*(.|\\v)*?\\*\\/ .
I only came up with this solution after googling al and with help from the forum, but I find it horrible to edit, and I cannot validate this with an external tool like regex101.com

Hi @roberting

Are you making use of the code generation function of regex101?

4 Likes

Hi @ArjenEX,
that’s an excellent hint!
I never used this feature before, but this will make life easier a lot!
(even if it doesn’t solve the actual question, why we need double escape chars at all.)

Hi @roberting, this may go some way towards helping explain the double-escaping within scripting languages :slight_smile:

2 Likes

Hi @ArjenEX ,
i made use of the generator but it does not alway give correct results. I have a strange effect of a string manipulation node with a regexReplace \\/\\*(.|\\v)*?\\*\\/ as proposed by the regex101 Code Generator (also like mentioned in my first post in this topic) to remove multiline comments from JS code.

Now the rule works just fine on my codes, but strangely results in a ‘missing’ cell for one particular code snippet, that otherwise looks good on regex101.com

if the regex was wrong and accidentally captured the whole string, I would expect to return an empty string cell, but missing seem strange to me.