0

I need to parse a string ; as a delimiter. But don't need to parse the text if it is within double quotes.

Example I need to parse

this ; "but not ; this"

For this I have come up with regex pattern which works fine.

;(?=(?:(?:[^\"]*\"){2})*[^\"]*$)

Now if text contains escaped quotes, the above pattern doesn't work.

I need to parse

this ; "but \" not ; this"

Could you help me with the pattern which omits escaped quotes within quotes?

nhahtdh
  • 55,989
  • 15
  • 126
  • 162

1 Answers1

0

As long as double quotes are not unbalanced you can use this regex with negative look-behind:

(?s);(?=(?:(?:.*?(?<!\\\\)\"){2})*[^\"]*$)

Working Demo: http://ideone.com/KmjJXJ

anubhava
  • 761,203
  • 64
  • 569
  • 643