Let\'s say I want to represent \\q (or any other particular \"backslash-escaped character\"). That is, I want to match \\q but not \\\\q
Updated: My new and improved Perl regex, supporting more than 3 backslashes:
/(?\\\\)* # an even number of backslashes \\q # Followed by a \q /x;
or if your regex library doesn't support extended syntax.
/(?\\\\)*\\q/
Output of my test program:
q does not match \q does match \\q does not match \\\q does match \\\\q does not match \\\\\q does match
Older version
/(?:(?