【发布时间】:2018-03-17 19:46:08
【问题描述】:
我有一些表格文本:
This is some text, and here's some in "double quotes"
"and here's a double quote:\" and some more", "text that follows"
文本包含双引号内的字符串,如上所示。双引号可以用反斜杠 (\) 转义。在上面,有三个这样的字符串:
"double quotes"
"and here's a double quote:\" and some more"
"text that follows"
为了提取这些字符串,我尝试了正则表达式:
"(?:\\"|.)*?"
但是,这给了我以下结果:
>>> preg_match_all('%"(?:\\"|.)*?"%', $msg, $matches)
>>> $matches
[
[ "double quotes",
"and here's a double quote:\",
", "
]
]
如何正确获取字符串?
【问题讨论】:
-
你几乎只是一个逃避问题。要转义反斜杠,您必须这样做
'%"(?:\\\\"|.)*?"%'。