In this way, how do I write the regular expression values in single and double symbols?

Source: Internet
Author: User
In this way, how do I write the regular expression values in single and double symbols? This post was last edited by u013670343 at 21:44:46

ProId: '20140901 ',
'Proid': '123 ',

First question: how do I write a regular expression that is 123456789 compatible with the above two lines of code?
That is, whether it is using proId: '123', the value in it,
Or take the value in 'proid': '123,
If you write only one regular expression, you can get the value!



'Newsid': '123 ',
NewsId: "987654321 ",

The second question: how do I write a regular expression that is 987654321 compatible with the above two lines of code?
Whether it is 'newsid': '123', the value in it,
Or take the value in newsId: "987654321,
If you write only one regular expression, you can get the value!


Reply to discussion (solution)

['] * (? : ProId | newsId) ['] *: \ s * ['] * (\ d +) ['] *

['] * (? : ProId | newsId) ['] *: \ s * [\' \ "] * (\ d +) [\ '\"] *

First question

$ S = <
   
  

Second question
$ S = <
    
    

First:
/(\ ') {0, 1} newsId (\') {0, 1} :( \ '| \ ") (\ d +) (\' | \"),/

Second
/(\ ') {0, 1} userId (\') {0, 1} :( \ s *?) {0, 1} \ '(\ d + )\',/

$s =<<< TXTproId:       '123456789','proId':'123456789','newsId':'987654321',newsId:"987654321",TXT;preg_match_all('/:\s*([\'"])(.+)\1/', $s, $r);print_r($r[2]);
Array
(
[0] = & gt; 123456789
[1] => 123456789.
[2] => 987654321.
[3] = & gt; 987654321
)

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.