2014-03-26 70 views
1

我有這樣的字符串(如Python DOC):正則表達式匹配3報價串

""" 
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 

回答

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" 

) 
代碼時