Regular anonymous capture named captures

Source: Internet
Author: User
Tags php error
know the power of regular expressions recently learned some, encounter problems, nonsense not much to say on the code:

$str = 'Mr.Ck-@139.com';if(preg_match('(?:<#user>[a-zA-Z0-9_-.]+)@(?:<#host>[a-zA-Z0-9_-.]+)', $str, $match)) {    print_r($match);}$str = '123,456,78,90';if(preg_match('(?[0-9]+)(.(?[0-9]+))*', $str, $match)) {    print_r($match);}

error message :

Warning:preg_match (): Unknown modifier ' @ D:\webServ\index.php on line 15

Warning:preg_match (): Unknown modifier ' (' in D:\webServ\index.php to line 23

I do not know whether it is because of the PHP function problem, I believe this expression should be no problem, just preg_match the function of what mechanism caused the put?

Reply content:

Know the power of regular expressions recently learned some, encounter problems, nonsense not much to say on the code:

$str = 'Mr.Ck-@139.com';if(preg_match('(?:<#user>[a-zA-Z0-9_-.]+)@(?:<#host>[a-zA-Z0-9_-.]+)', $str, $match)) {    print_r($match);}$str = '123,456,78,90';if(preg_match('(?[0-9]+)(.(?[0-9]+))*', $str, $match)) {    print_r($match);}

error message :

Warning:preg_match (): Unknown modifier ' @ D:\webServ\index.php on line 15

Warning:preg_match (): Unknown modifier ' (' in D:\webServ\index.php to line 23

I do not know whether it is because of the PHP function problem, I believe this expression should be no problem, just preg_match the function of what mechanism caused the put?

    • preg_matchThe first parameter is a regular string, and the regular requires the start and end tags you don't have here.
'(?:<#user>[a-zA-Z0-9_-.]+)@(?:<#host>[a-zA-Z0-9_-.]+)'(?[0-9]+)(.(?[0-9]+))*

Switch

'/(?:<#user>[a-zA-Z0-9_-.]+)@(?:<#host>[a-zA-Z0-9_-.]+)/''/(?[0-9]+)(.(?[0-9]+))*/'
    • After the above changes are still wrong, the reason for the error is:

      • _-.The lines within the brackets - have special meanings (refer a-z to, 0-9 ).
      • The second regular in (? this notation is incorrect, PHP error message is:
        Warning: preg_match(): Compilation failed: unrecognized character after (? or (?- at offset 2 in T:\1.php on line xxBecause do not know your second specific to do what, you can directly delete the ? number, or the number after the number to ? : solve the problem of error.

The code after the change:

php
  
   [a-zA-Z0-9_\-.]+)@(?:<#host>[a-zA-Z0-9_\-.]+)/', $str, $match)) {    print_r($match);}$str = '123,456,78,90';if(preg_match('/([0-9]+)(.([0-9]+))*/', $str, $match)) {    print_r($match);}

I solved the number, the final question.

  • Related Article

    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.