PHP, regular expressions
You prawns, I am a programming enthusiast, beginner PHP, encountered a regular expression matching problem, baffled, special to ask for advice.
My code is as follows:
<title>The first page of PHP</title>
$str = "Akk C";
$pattern = "/(.) \1/";
Echo Preg_match ($pattern, $str, $matches). "
";
Var_dump ($matches);
?>
It is supposed to be able to match "KK", but the output is:
0
Array (size=0)
Empty
Thank you!
Another: My environment configuration is:
Server version: 5.6.12-log-mysql Community server (GPL)
apache/2.4.4 (Win64) php/5.4.12
Reply to discussion (solution)
If you want to match KK,
$str = "Akk c"; $pattern = "/k+/"; Echo Preg_match ($pattern, $str, $matches). "
"; Var_dump ($matches);
Or so
$str = "Akk c"; $pattern = "/(.) \\1/"; Echo Preg_match ($pattern, $str, $matches)."
"; Var_dump ($matches);
Thank you for your guidance. I forgot to state that I was trying to test the matching function of the regular "\num".
Thanks a lot! I can do it!
It is best to use single quotes when writing regular, and double quotes to handle many escapes, so add a lot of \
For example, \1 will be considered \x01 and must be written \\1 to handle it correctly.
Yes, I appreciate that, thank you.
Upstairs teachers: Sorry, I am new, do not know the "checkout to points" This procedure, not timely performance, please forgive, thank you again!