I have to parse a regular expression which can contain special symbols such as \s and \d. The problem is, I can't distinguish the \ when i am parsing the expression, I mean '\s' == 's', therefore I cannot distinguish between special character and basic character. How can I solve this?
2 Answers
Raw string literals since C++11 can help you to improve the readability:
"a\\sb" // matches: a[whitespace]b "a\\\\sb" // matches: a\sb becomes:
R"(a\sb)" // matches: a[whitespace]b R"(a\\sb)" // matches: a\sb 1 Comment
Martin Bonner supports Monica
I think your second examples should read "
matches: a\\sb" - note the "s" before the "b"
a\sbwhich will be different fromasb, but i cannot catch the single *\* to parse it properly