Reputation: 4724
I have a set of strings in the below format, i want to capture the value inside the double quotes.
Input:
"icici","1001","50.0"
"hdfc","2001","10.0","20.0"
Expected output from substitution parameter:
\0 match icici and hdfc
\1 match 1001 and 2001
\2 match 50.0 and 10.0
\3 match 20.0
I tried the below regex but its not working properly, could you please help?
((?:")([0-9A-Za-z.]+)(?:",?))+
Upvotes: 1
Views: 117
Reputation: 3299
try this:
/\"([a-z0-9.]+)\"/mi
allow character puts in [allow char]
php
$re = "/\"([a-z0-9.]+)\"/mi";
$str = "\"icici\",\"1001\",\"50.0\"\n\"hdfc\",\"2001\",\"10.0\",\"20.0\"";
preg_match_all($re, $str, $matches);
var_dump( $matches[1]);
or
$str="";
if(count($matches[1])>0) foreach($matches[1] as $k=>$v){
$str .="\\$k"."->".$v." ";
}
echo $str ;
output:
array (size=7)
0 => string 'icici' (length=5)
1 => string '1001' (length=4)
2 => string '50.0' (length=4)
3 => string 'hdfc' (length=4)
4 => string '2001' (length=4)
5 => string '10.0' (length=4)
6 => string '20.0' (length=4)
or
\0->icici \1->1001 \2->50.0 \3->hdfc \4->2001 \5->10.0 \6->20.0
Upvotes: 0