I’m doing a non-greedy match like this
'(?<C2>.+?)'
to find a group inside a quotes. This works well, until I want to do something like this
'(?<C2>.+?)' as
to match something in quotes followed by a space, following by the word as.
But now, the following will not match as desired
'hello'123'hello2' as
I want this to not match at all…but it ends up matching the whole chunk
'hello'123'hello2'
as C2
What’s the best way to force the non-greedy .+? to include up to the first occurance of a ', not the first occurance of ' as
This seems to work
Explanation
Even without the lookahead
(?= as),(?<C2>'[^']+')will match quoted strings in a non-greedy way as expected.