Php5 and mysql5web development technical details-5 regular expressions. RegularExpression is a concise and flexible expression for searching and replacing string patterns. It is not difficult to understand the importance, but without some practice, Regular Expression is a concise and flexible Expression for searching and replacing string patterns.
It is not difficult to understand the importance. However, it is not easy to implement flexible applications without some practice.
In php, there are two types of regular expressions: POSIX and PCRE.
First, simply list the main content, and then add instructions and instances.
I. POSIX (Portable Operating System Implementation for Unix), which means Unix can be transplanted to the Operating System Implementation interface.
1. ^ and $ delimiters
2. quantifiers or qualified words
*
+
?
{N}
{N ,}
{N, m}
3. square brackets
[AAeEiIoOuU] character cluster of all vowel characters
[0-9] [a-z]
4. pre-defined character clusters (built-in generic character clusters, specifying the character processing range)
[[: Alpha:] uppercase and lowercase letters, same as [a-zA-Z]
[[: Digit:] number, same as [0-9]
[[: Alnum:] uppercase and lowercase letters and numbers, same as [a-zA-Z0-9]
[[: Cntrl:] control characters, including Tab, return, or backslash
[[: Space:] any white characters, including spaces, tabs, line breaks, page breaks, and carriage returns
......
Do not list them one by one
5. Regular Expression functions
Ereg (condition, <原始字符串> )
Eregi () is case insensitive
Ereg_replace (): added the character replacement function based on ereg ().
Eregi_replace ()
Split () splits the string into arrays based on the delimiter in the string
Spliti ()
SQL _regcase ()
6. POSIX submode
II. PCRE (Perl Compatible Regular Expression)
1. character clusters
\ B
\ D
\ S
\ T
\ W
2. matching
Delimiter/is used at the beginning and end of the expression. after the last separator/, you can add a modifier.
I, M, S, X, U, DU
You can also use a variety of metacharacters, similar to POSIX locators and character clusters.
\ A, \ B, \ B, \ d, \ D, \ s, \ S, [], (), ^, $,., \, \ w, \ W
3. function www.2cto.com
Preg_match ():
Example: preg_match ('/^ [[: alnum] {4, 8} $/', $ username)
Preg_match_all ()
Preg_quote (): add a conversion character
Preg_split ():
Preg_grep ()
Preg_replace (): Replace
Preg_replace_callback ()
Regular (Regular Expression) is a concise and flexible Expression for searching and replacing string modes. It is not difficult to understand the importance, but if there is no practice, do it...