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_match
The 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 xx
Because 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.