How can I match double-quoted strings with escaped double-quote characters?

前端 未结 7 1193
既然无缘
既然无缘 2020-12-05 00:08

I need a Perl regular expression to match a string. I\'m assuming only double-quoted strings, that a \\\" is a literal quote character and NOT the end of the string, and tha

相关标签:
7条回答
  • 2020-12-05 01:00

    /"(?:[^\\"]|\\.)*"/

    This is almost the same as Cal's answer, but has the advantage of matching strings containing escape codes such as \n.

    The ?: characters are there to prevent the contained expression being saved as a backreference, but they can be removed.

    NOTE: as pointed out by Louis Semprini, this is limited to 32kb texts due a recursion limit built into Perl's regex engine (that unfortunately silently returns a failure when hit, instead of crashing loudly).

    0 讨论(0)
提交回复
热议问题