Regular Expression Matching problem This post was last edited by ConRst in 2013-03-0416: 19: 37 as the string & amp; AAA = 111 & amp; BBB = 222 & amp; CCC = 333... now we want to use regular matching to get values like AAA and 111 $ RegStr = '/& amp; regular expression matching.
At the end of this post, ConRst edited the string at 16:19:37 on.
& AAA = 111 & BBB = 222 & CCC = 333...
Now we want to obtain values like AAA and 111 through regular matching.
$ RegStr = '/& (. *) = (. *)/'; // Is there a problem with this expression? the output result here is incorrect.
If (preg_match ($ RegStr, $ urladd, $ mat ))
{
Print_r ($ mat); // How to output values of two variables, AAA and 111
}
There is a problem with the above code output. I posted it to help you understand it. please help me.
------ Solution --------------------
$ RegStr = '/&(.*?) = ([^ &] + )/';
------ Solution --------------------
$str='&AAA=111&BBB=222&CCC=333';
preg_match_all('/&(\w+)=(\w+)/i',$str,$result);
var_dump($result);
Array (3 ){
[0] =>
Array (3 ){
[0] =>
String (8) "& AAA = 111"
[1] =>
String (8) "& BBB = 222"
[2] =>
String (8) "& CCC = 333"
}
[1] =>
Array (3 ){
[0] =>
String (3) "AAA"
[1] =>
String (3) "BBB"
[2] =>
String (3) "CCC"
}
[2] =>
Array (3 ){
[0] =>
String (3) 111"
[1] =>
String (3) 222"
[2] =>
String (3) 333"
}
}