I’m using ANTLR to make a simple language, and right now I’m trying to implement escape characters into my strings, what I have now is:
String : ["] ( ~["\r\n\\] .*? | .*? '\\' ~[\r\n] )* ["] ;
However, whenever I feed it an input like
It discards the
\, leaving me with
Test 1234n, which won’t work. Is there a RegEx to match any String and keep the back slashes?
Here’s a regex that matches a quoted string of letters, numbers, spaces and backslashes but only when the backslash is followed by r or n:
See live demo.
Answered By – Bohemian
Answer Checked By – Cary Denson (BugsFixing Admin)