I need to find a pattern in a string (e.g. character '}' or anything else) but this pattern may occur inside a quoted string and, naturally, I don't want my regex to capture it.
Example:
bla bla } bla bla <-- Capture.
bla "bla bla" } bla <-- Capture.
bla bla } "bla bla" <-- Capture.
bla "bla } bla" bla <-- DON'T capture.
bla } bla "bla } bla" <-- Capture the first, but DON'T capture second.
I need to accomplish this using C++14 std::regex
(so no lookbehind).
I gathered some inspiration in the links below but none fully solves my problem and I assume I am not being very clever to solve it myself:
- A regex to detect string not enclosed in double quotes
- Regex to find content not in quotes
- Regular Expressions Quick Start (and sublinks)
- using regex to replace words not enclosed in <> signs
- regex101.com
As you can see, no much about C++ regexes and even considering PHP, Javascript, Perl, etc. I cannot find an answer.
Any help will be greatly appreciated. Thanks in advance.