What's the regex to match anything except a double quote not preceded by a backslash?

后端 未结 2 1207
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 04:32

In other words, I have a string like:

\"anything, escaped double-quotes: \\\", yep\" anything here NOT to be matched.

How do I match everything inside the qu

2条回答
  •  清歌不尽
    2020-12-06 05:17

    "Not preceded by" translates directly to "negative lookbehind", so you'd want (?.

    Though here's a question that may ruin your day: what about the string "foo\\"? That is, a double-quote preceded by two backslashes, where in most escaping syntaxes we would be wanting to negate the special meaning of the second backslash by preceding it with the first.

    That sort of thing is kind of why regexes aren't a substitute for parsers.

提交回复
热议问题