Consider following string
"Some" string with "quotes" and \"pre-slashed\" quotes
Using regex, I want to find all the double quotes with no slash before them. So I want the regex to find four matches for the example sentence
This….
[^\\]"
…would find only three of them. I suppose that’s because of the regex’s state machine which is first validating the command to negate the presence of the slash.
That means I need to write a regex with some kind of look-behind, but I don’t know how to work with these lookaheads and lookbehinds…im not even sure that’s what I’m looking for.
The following attempt returns 6, not 4 matches…
"(?<!\\)
Is what you’re looking for
If you want to match “Some” and “quotes”, then
will do
Explanation:
(?<!\\")– Negative lookbehind. Specifies a group that can not match before your main expression(?!\\")– Negative lookahead. Specifies a group that can not match after your main expression"[a-zA-Z0-9]*"– String to match between regular quotesWhich means – match anything that doesn’t come with \” before and \” after, but is contained inside double quotes