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: