The problem of regular expression matching
This post was last edited by Conrst on 2013-03-04 16:19:37
The string is like this
&aaa=111&bbb=222&ccc=333 ...
Now I want to get the AAA and 111 values with a regular match.
$RegStr = '/& (. *) = (. *)/'; Is there a problem with this expression I'm not going to get the output here?
if (Preg_match ($RegStr, $urladd, $mat))
{
Print_r ($mat); Here's how to output the value of two variables such as AAA and 111
}
The above code output has a problem, paste it out is to let everybody see understand, please everybody help
------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"
}
}