Questions about PHP regular expression matching

Source: Internet
Author: User
I am a programmer and a beginner in PHP. I have encountered a regular expression matching problem, so I am eager to explain it. My code is as follows: & lt ;! DOCTYPE & nbsp; HTML & gt; & lt; html & nbsp; lang = "zh-CN" & g tutorial on PHP regular expression matching
I am a programmer and a beginner in PHP. I have encountered a regular expression matching problem, which is hard to understand. I 'd like to ask for advice.
My code is as follows:




First PHP webpage



$str = "akk c";
$pattern="/(.)\1/";
echo preg_match($pattern,$str,$matches)."
";
var_dump($matches);
?>




The output result is:
0
Array (size = 0)
Empty

Thank you!

In addition, my environment configuration is:
Server version: 5.6.12-log-MySQL Community Server (GPL)
Apache/2.4.4 (Win64) PHP/5.4.12
Php, regular expressions shared: ... 'Data-pics = ''>
------ Solution --------------------
If you want to match kk



$str = "akk c";
$pattern="/k+/";
echo preg_match($pattern,$str,$matches)."
";
var_dump($matches);


------ Solution --------------------
Or



$str = "akk c";
$pattern="/(.)\\1/";
echo preg_match($pattern,$str,$matches)."
";
var_dump($matches);


------ Solution --------------------
It is best to use single quotation marks when writing regular expressions. double quotation marks will handle a lot of escape operations, so you need to add a lot \
For example, \ 1 is regarded as \ x01 and must be written as \ 1 to be processed correctly.

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.