正则表达式匹配“”之间的任何

时间:2021-04-24 09:37:55

The text is: "I like to watch.","\"I like to watch.\""

文字是:“我喜欢看。”,“\”我喜欢看。“”

I want break the text into "I like to watch." and "\"I like to watch.\""

我想把文字分成“我喜欢看”。和“\”我喜欢看。“”

use "[\w\W]+?"

but get "I like to watch.","\",

但得到“我喜欢看。”,“\”,

What's the right expression?

什么是正确的表达方式?

1 个解决方案

#1


2  

You need to use

你需要使用

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

See the regex demo.

请参阅正则表达式演示。

Details:

  • " - a double quote
  • “ - 双引号

  • [^"\\]* - any 0+ chars other than a double quote and a backslash
  • [^“\\] * - 除了双引号和反斜杠之外的任何0+字符

  • (?:\\.[^"\\]*)* - zero or more sequences of:
    • \\. - a backslash and any char other than a line break char
    • \\。 - 反斜杠和除换行符之外的任何字符

    • [^"\\]* - any 0+ chars other than a double quote and a backslash
    • [^“\\] * - 除了双引号和反斜杠之外的任何0+字符

  • (?:\\。[^“\\] *)* - 零个或多个序列:\\。 - 反斜杠和除换行符之外的任何字符char [^”\\] * - 任何0+字符其他而不是双引号和反斜杠

  • " - a double quote
  • “ - 双引号

#1


2  

You need to use

你需要使用

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

See the regex demo.

请参阅正则表达式演示。

Details:

  • " - a double quote
  • “ - 双引号

  • [^"\\]* - any 0+ chars other than a double quote and a backslash
  • [^“\\] * - 除了双引号和反斜杠之外的任何0+字符

  • (?:\\.[^"\\]*)* - zero or more sequences of:
    • \\. - a backslash and any char other than a line break char
    • \\。 - 反斜杠和除换行符之外的任何字符

    • [^"\\]* - any 0+ chars other than a double quote and a backslash
    • [^“\\] * - 除了双引号和反斜杠之外的任何0+字符

  • (?:\\。[^“\\] *)* - 零个或多个序列:\\。 - 反斜杠和除换行符之外的任何字符char [^”\\] * - 任何0+字符其他而不是双引号和反斜杠

  • " - a double quote
  • “ - 双引号