Home  >  Article  >  Backend Development  >  Detailed explanation of php5 and mysql5 web development technology-5 Regular expression_PHP tutorial

Detailed explanation of php5 and mysql5 web development technology-5 Regular expression_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:09:031009browse

Regular expression (Regular Expression) is a concise and flexible notation for finding and replacing string patterns.

I won’t go into details about the importance. It is not difficult to understand, but without certain practice, it is not easy to apply it flexibly.
In php, regular expressions are divided into two specifications: POSIX and PCRE.
First briefly list the main content, and then add explanations and examples later.
1. POSIX (Portable Operating System Implementation for Unix), which means Unix portable operating system implementation interface.
1, ^ and $ locators
2. Quantifier or determiner
*
+
?
{n}
{n,}
{n,m}
3. Square bracket expression
[aAeEiIoOuU] Character cluster for all vowel characters
[0-9] [a-z]
4. Predefined character cluster (built-in universal character cluster, specifying the processing range of characters)
[[:alpha:]] Uppercase and lowercase letters, the same as [a-zA-Z]
[[:digit:]] Number, same as [0-9]
[[:alnum:]] Uppercase and lowercase letters and numbers, the same as [a-zA-Z0-9]
[[:cntrl:]] Control characters, including Tab, backspace or backslash
[[:space:]] Any white characters, including space, tab, line feed, form feed and carriage return
 …
Not listed one by one
5. Regular expression function
ereg(condition, )
eregi() is not case sensitive
ereg_replace() : Based on ereg(), the character replacement function is added
eregi_replace()
split() splits the string into an array based on the delimiter in the string
spliti()
sql_regcase()
6, POSIX sub-mode
2. PCRE (Perl Compatible Regular Expression)
1. Character cluster
\b
\d
\s
\t
\w
2. Match
Use the delimiter / at the beginning and end of the expression. After the last delimiter /, you can add the modifier
I ,M ,S,X,U,DU
You can also use various metacharacters, similar to POSIX combinations of 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 escape character
preg_split():
preg_grep()
preg_replace(): Replace
preg_replace_callback()

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477713.htmlTechArticleRegular Expression (Regular Expression) is a concise and flexible notation for finding and replacing string patterns. I won’t go into details about the importance, it’s not difficult to understand, but if you don’t have some practice, do...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn