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 -
(?:\\.[^"\\]*)*
- 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+字符
-
-
"
- a double quote
“ - 双引号
[^“\\] * - 除了双引号和反斜杠之外的任何0+字符
(?:\\。[^“\\] *)* - 零个或多个序列:\\。 - 反斜杠和除换行符之外的任何字符char [^”\\] * - 任何0+字符其他而不是双引号和反斜杠
“ - 双引号
#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 -
(?:\\.[^"\\]*)*
- 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+字符
-
-
"
- a double quote
“ - 双引号
[^“\\] * - 除了双引号和反斜杠之外的任何0+字符
(?:\\。[^“\\] *)* - 零个或多个序列:\\。 - 反斜杠和除换行符之外的任何字符char [^”\\] * - 任何0+字符其他而不是双引号和反斜杠
“ - 双引号