[quote=262333:@Jean-Yves Pochez]I remember seeing here on the forum that regex is NOT a parser and should not be use that way…
use a real parser for that.[/quote]
A character class (square brackets surrounding one or more tokens) will only match one character in the source text. Every token within it is treated individually so your pattern will match either a backslash or an x.
Mark’s suggestion is a good one, and you can also do this:
[yn]|\\\\x
If that constitutes the entire patten, no parens are needed.
[quote=262338:@Kem Tekinay]A character class (square brackets surrounding one or more tokens) will only match one character in the source text. Every token within it is treated individually so your pattern will match either a backslash or an x.
Mark’s suggestion is a good one, and you can also do this:
[yn]|\\\\x
If that constitutes the entire patten, no parens are needed.[/quote]
I was not aware that the ‘|’ could be used without the parens, I’ve only seen it written as ‘(a|b)’. Thanks.