Regular Expression Matching problems

Source: Internet
Author: User
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"
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.