I just read a new question here on SO asking basically the same thing as mine does in the title. That got me thinking - and searching the web (most hits pointed to SO, of co
I've considered the comments (so far) and changed the regex to:
(?:\/\/(?:\\\n|[^\n])*\n)|(?:\/\*[\s\S]*?\*\/)|((?:R"([^(\\\s]{0,16})\([^)]*\)\2")|(?:@"[^"]*?")|(?:"(?:\?\?'|\\\\|\\"|\\\n|[^"])*?")|(?:'(?:\\\\|\\'|\\\n|[^'])*?'))
It handles Biffens C++11's raw string literal (as well as C# verbatim strings) and it's changed according to Wiktors suggestions.
Split it to handling single and double quotes separately because of difference in logic (and avoiding the non-working back reference ;).
It's undoubtedly more complex, but still far from the solutions I've seen out there which hardly cover any of the string issues. And it could be stripped of parts not applicable to a specific language.
One comment suggested supporting more languages. That would make the RE (even more) complex and unmanageable. It should be relatively easy to adapt though.
Updated regex101 example.
Thanks everyone for the input so far. And keep the suggestions coming.
Regards
Edit: Update Raw String - this time I actually read the spec. ;)