我有这个字符串(比如python doc):
"""
1 string with two lines
in this area
"""
"""
2 string, but with more "quotes"
"""
"""
3 string
multiline and "multiquote"
"""
我需要:
array(
[0] => 1 string with two lines
in this area
[1] => 2 string, but with more "quotes"
[2] => 3 string
multiline and "multiquote"
)
但是,我有:
/(?<!""")(?<=(?!""").)"(?!""")/im
和
/(\x22\x22\x22)[\w\s\d\D\W\S.]+(?\x22\x22\x22)/i
答案 0 :(得分:2)
preg_match_all("/\"{3}(.*?)\"{3}/s", $str, $matches);
答案 1 :(得分:2)
为什么你不像这样编码
$re = '/"""(.*?)"""/is';
$str = '"""
1 string with two lines
in this area
"""
"""
2 string, but with more "quotes"
"""
"""
3 string
multiline and "multiquote"
"""';
preg_match_all($re, $str, $matches);
echo "<pre>";
print_r($matches[1]);
output:
Array
(
[0] =>
1 string with two lines
in this area
[1] =>
2 string, but with more "quotes"
[2] =>
3 string
multiline and "multiquote"
)