Regular expression metacharacters

Source: Internet
Author: User
Tags php tutorial

Regular expression (regular expression) "metacharacters ":

* Match the previous content zero or multiple times, that is, the previous content matches any one

. Match content 0 times 1 time or multiple times, but does not contain carriage return line breaks

+ Match the previous content once or multiple times (except null ).

| Select matching similar to in PHP | (because this operation conforms to the weak type, leading to the most overall match)

^ Match the first part of a string

$ Match string tail content

{A, B} indicates the number of times the previous content is matched. This indicates the number of times from a to B.

() Merge the overall match and put it into the memory. You can use 1 2... Obtain

Below is an example I wrote in the php Tutorial:

<? Php

$ Mode = "/d {2, 4} (. *) d {1, 2} \ 1d {1, 2}/"; // The simpler the matching module, the better.
// $ Mode = "/2009 (.. *) 9 \ 1 (10 )/";
$ Str = "2011/9/10 ";
If (preg_match ($ mode, $ str, $ arr )){
Echo "matched ". "<br/> <font color = red> ". $ arr [0]. "</font> <br/> <font size = '+ 4' color = blue> happy teachers' day </font> ";
}
Else {
Echo "matching failed ";
 }

?>

Result:

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.