Reputation: 3520
I have the next string:
$string = '["["123456","NAME","1","INFORMATION","15/12/2015","","","0","OTHER ATTRIBUTE","",""]","["["123", "OTHER"]"';
I want to extract the alphanumeric information between double quotes, I tried with this answer
Regex to get content between single and double quotes php
but the output was this,
[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) "]" }
How can I achieve this?
Upvotes: 2
Views: 175
Reputation: 18490
Your input "["123456"
... is different to the link you mentioned. And no single quote here.
An idea would be to require a \w
word character in pattern for at least one [A-Za-z0-9_]
if(preg_match_all('/"([^"]*?\w[^"]*)"/', $string, $out) > 0)
print_r($out[1]);
[^"]*
matches any amount of characters, that are not "
. The ?
after *
makes it lazy.$1
what's captured by first capture group (parenthesized group).See demo and more explanation at regex101 or PHP demo at eval.in
Upvotes: 1
Reputation: 1015
Try this regey with preg_match_all :
\"[^\"\,\[\]]+\"
You can test it here : http://www.phpliveregex.com/p/eKH
Upvotes: 1