Regex formatting #408
-
So, I'm a bit lost on the why or why not the regex patterns have different ways of escaping characters depending on which part of the app they are on. So for example
But why? I vaguely remember there was some discussion about this, but I can't find it, maybe I'm just imagining it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't remember any discussion, but maybe an old one exists somewhere. As for the actual question, the answer is: there is only a single way. Java regex doesn't require you to escape the forward slash So basically: all three ways That was the short explanation for those of you who already know some details, now let me try to explain it step by step for those who want a more in depth explanation. What you write with your keyboard in the json editor is actually a multiline string, let's say you write this: {
"regex": "1\\\/2\/3/4"
} This string contains the character This multiline string is then sent to the JSON decode function, which takes the string and returns a java JSON node with the parsed data. This node is of type object (because of the Now, this string value is sent to the java regex engine to be used as a regex pattern, which means that One important thing to notice is that, even if you write simply |
Beta Was this translation helpful? Give feedback.
I don't remember any discussion, but maybe an old one exists somewhere.
As for the actual question, the answer is: there is only a single way. Java regex doesn't require you to escape the forward slash
'/'
but some other languages like JavaScript need it, so probably the url cleaner catalog authors did it just in case. In a regex, writingfoo/bar
is the same asfoo\/bar
. Then, the json editor requires the regex to be a string inside, and even though you don't need to escape the slashes, and"foo/bar"
is perfectly valid, you can do so if you want which means that"foo\/bar"
and"foo\\\/bar"
are also valid and represent the same.So basically: all three ways
/
\/
and\\\/
represent the same/
…