4

I am looking for a regular expression to match a string that can contain anything except single quotes, but if the quotes are escaped, it should be matched.

Essentially, i want to match the String "Tuco" and "Tuco\"ABC" but not "Tuco"";

It looks like the following doesnot match the quotes but fails to match the quote.

"^((?!\").)*$"

What would be the right regex.

Thanks

Essentially i am looking for any valid double quoted string, with possible escape characters if any..

Tuco
  • 712
  • 2
  • 8
  • 20

1 Answers1

4

Seems that you are looking for an expression for a double quoted string with possible escapes:

"(?:[^"\\]+|\\.)*"
Qtax
  • 33,241
  • 9
  • 83
  • 121