firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.25k stars 199 forks source link

JavaScript regular string delims use the same escapes as regexp delims #2245

Closed cD1rtX3 closed 6 months ago

cD1rtX3 commented 6 months ago

In actual JavaScript, the string "\\\\" matches a single backslash, and the expression /\\/ also matches a single backslash. This is because a "\\" is one backslash in a RegExp. Something like "\n" puts a literal newline in the string, while "\\n" matches a newline.

This behaviour is not mirrored in RegEx101.

working-name commented 6 months ago

Hello @cD1rtX3

Please keep in mind that what you're testing on regex101.com is pure regex. It's not a javascript IDE environment, in fact none of the flavors do any parsing of your input by that language (python doesn't parse your input, and then passes it to the regex engine for example). For that function, please see the code generator in the left sidebar.

As far as consistency in string processing with javascript... good luck! image Here's another interesting javscript parsing crap (the third \ escapes the character a): image

firasdib commented 6 months ago

This is simply the effect of string parsing in the respective languages. It's nothing that regex101 cares about, as it has nothing to do with the actual regex testing. If you try out the code generator, it should help create a code sample that you can run in JS.