Regular Expression Matching URL parameters

Source: Internet
Author: User
Find a regular expression that matches URL parameters, such as www.sina.com. cnsports? P3456www.sina.com. cnsports? Why 923www.sina.com. cnsportsbasktball? P878923 need to match now? The parameter in p is the added black part. I used the method to find a regular expression that matches the URL parameter.
For example
Http://www.sina.com.cn/sports? P = 3456

Http://www.sina.com.cn/sports? P = 38923

Http://www.sina.com.cn/sports/basktball? P = 878923

Need to match now? P = the parameter in it is the black part.
The method I use is,
^ /? ([A-z/] + )/\? P = ([0-9] +)
Can match the previous parameter, but there is no way to match "? = P "is followed by a number parameter. how can I write this regular expression? Thank you!


------ Solution --------------------
Preg_match ('/p = (\ d +)/', $ s, $ m );
Echo $ m [1];
------ Solution --------------------
2 loou good
------ Solution --------------------
Preg_match ('/(? <= \? P =) \ d +/', $ str, $ match );
Echo $ match [0];
------ Solution --------------------

(? <= P \ =) \ d +

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.