我有下一个字符串:
$string = '["["123456","NAME","1","INFORMATION","15/12/2015","","","0","OTHER ATTRIBUTE","",""]","["["123", "OTHER"]"';
我想在双引号之间提取字母数字信息,我试着用这个答案
Regex to get content between single and double quotes php
但输出是这个,
[0]=> array(12) { [0]=> string(3) ""["" [1]=> string(3) "","" [2]=> string(3) "","" [3]=> string(3) "","" [4]=> string(3) "","" [5]=> string(3) "","" [6]=> string(3) "","" [7]=> string(3) "","" [8]=> string(3) "","" [9]=> string(3) "","" [10]=> string(3) "","" [11]=> string(3) ""]"" } [1]=> array(12) { [0]=> string(1) """ [1]=> string(1) """ [2]=> string(1) """ [3]=> string(1) """ [4]=> string(1) """ [5]=> string(1) """ [6]=> string(1) """ [7]=> string(1) """ [8]=> string(1) """ [9]=> string(1) """ [10]=> string(1) """ [11]=> string(1) """ } [2]=> array(12) { [0]=> string(1) "[" [1]=> string(1) "," [2]=> string(1) "," [3]=> string(1) "," [4]=> string(1) "," [5]=> string(1) "," [6]=> string(1) "," [7]=> string(1) "," [8]=> string(1) "," [9]=> string(1) "," [10]=> string(1) "," [11]=> string(1) "]" }
我怎样才能做到这一点?
答案 0 :(得分:1)
答案 1 :(得分:1)
您的输入"["123456"
...与link you mentioned不同。这里没有单引号。
一个想法是要求\w
word character模式至少有一个[A-Za-z0-9_]
if(preg_match_all('/"([^"]*?\w[^"]*)"/', $string, $out) > 0)
print_r($out[1]);
[^"]*
匹配任意数量的字符,即not "
。 ?
之后的*
使其成为lazy。$1
中找到第一个capture group(括号内组)捕获的内容中的匹配项。See demo and more explanation at regex101或PHP demo at eval.in