Overview:
A regular expression is a matching pattern and is also a string (just some syntax rules, special characters ) in this string.
The regular expression of this string, must be used in the corresponding function, such as split function, replace function, find function, matching function.
Use the Pcre function to represent a regular expression (compatible with Perl)
Regular Expression composition: delimiter, Atom, metacharacters, pattern modifier
1, delimiter: In the string double quotation marks with the//number or other ({}, etc.) to do the delimiter, such as "/efgrehrt/"
2, Atom: The character that needs to be matched is an atom (the smallest matching unit, placed in the delimiter), and if the atom is a special character , such as/, then it needs to be escaped with \ to become \/. There is at least one atom in the regular expression .
(1) Atoms include print characters (A-Z-A-Z 0_9!@ #等) and nonprinting characters (carriage return \n,\.), escape characters \ can turn meaningful characters into meaningless atomic characters.
3, metacharacters: metacharacters cannot be used alone, it is used to extend atomic functions and to define functions (written in delimiters). For example, {5} in "/7{5}/" is a meta-character, which indicates that atomic 7 must appear 5 times
4, pattern modifier: fix, correct the pattern (regular) (the entire expression is corrected, written on the outside of the delimiter, to the right). For example "/a{5}/i", plus I is not case sensitive
Regular Expressions need to be placed in functions to be used: for example $str = "AA3AA4AA5AA6AA8AAA9AA" $reg = "/\d/" Preg_replace ($reg, "C", $str), replacing numbers in $str with C characters
The above describes the use of regular expressions in PHP programs, including special characters, regular expression aspects of the content, I hope that the PHP tutorial interested in a friend helpful.