-1

Let's say I have a string I want to match: banana. The problem is that I want to check whether this string is inside of double quotes. I've read that you can count the amount of double quotes in the whole line:

(?<!')banana(?=[^"]*(?:"[^"]*"[^"]*)*$).*$

However it doesn't match that string if I have input such as this:

"nope" banana "

In this case I still want the string to be matched (avoid nested quotes), so it means I need to count amount of double quotes BEFORE the string. How can I do that? P.S. I use onigurama in vscode extension

Gama11
  • 31,714
  • 9
  • 78
  • 100

1 Answers1

0

As I understand a question you need something like this: \G(?>".*?"|.)*?\Kbanana

Michail
  • 843
  • 4
  • 11
  • If I haven't made that clear, I want a regex which matches word banana if the amount of double quotes before this word is even. Your one doesn't seem to work – massacre123 Apr 15 '18 at 12:37
  • "Your one doesn't seem to work". Here is a test: https://regex101.com/r/2m0MGE/2 What subject string not matched by this regex? – Michail Apr 15 '18 at 12:46
  • I meant it doesn't work in my onigurama vscode environment – massacre123 Apr 15 '18 at 15:03