How to describe the use of the MySQL Express expression _php tutorial

Source: Internet
Author: User
Tags character classes
A regular expression defines a rule for a string. The simplest regular expression does not contain any reserved words. For example, the regular expression hello only matches the string "Hello".
Regular expressions use some special structure, so they can match more strings. For example, the regular expression Hello|word can match both the string "Hello" and the string "word". To take a more complicated example, the regular expression b[an]*s can match the string "Bananas", "Baaaaas", "BS", and any other string that ends with B in the middle, which can include any combination of a and any n.

The following reserved words can be used in a regular expression
^
The matched string begins with a string that follows
mysql> Select "Fonfo" RegExp "^fo$"; -0 (indicates mismatch)
mysql> Select "Fofo" RegExp "^FO"; --1 (indicates a match)
$
The matched string ends with the preceding string
Mysql> Select "Fono" RegExp "^fono$"; --1 (indicates a match)
Mysql> Select "Fono" RegExp "^fo$"; -0 (indicates mismatch)
.
Match any character (including new lines)
mysql> Select "Fofo" RegExp "^f.*"; --1 (indicates a match)
mysql> Select "Fonfo" RegExp "^f.*"; --1 (indicates a match)
A *
Match any number of Aces (including empty strings)
mysql> Select "Ban" RegExp "^ba*n"; --1 (indicates a match)
mysql> Select "Baaan" RegExp "^ba*n"; --1 (indicates a match)
Mysql> select "bn" RegExp "^ba*n"; --1 (indicates a match)
A +
Match any number of a (not including empty strings)
mysql> Select "Ban" RegExp "^ba+n"; --1 (indicates a match)
Mysql> select "bn" RegExp "^ba+n"; -0 (indicates mismatch)
A?
Match one or 0 a
Mysql> select "bn" RegExp "^ba?n"; --1 (indicates a match)
mysql> Select "Ban" RegExp "^ba?n"; --1 (indicates a match)
mysql> Select "Baan" RegExp "^ba?n"; -0 (indicates mismatch)
De|abc
Match de or ABC
mysql> Select "PI" RegExp "Pi|apa"; --1 (indicates a match)
Mysql> select "Axe" RegExp "Pi|apa"; -0 (indicates mismatch)
Mysql> Select "APA" RegExp "Pi|apa"; --1 (indicates a match)
Mysql> Select "APA" RegExp "^ (Pi|apa) $"; --1 (indicates a match)
mysql> Select "PI" regexp "^ (Pi|apa) $"; --1 (indicates a match)
mysql> select "Pix" RegExp "^ (Pi|apa) $"; -0 (indicates mismatch)
(ABC) *
Match any number of ABC (including Empty strings)
mysql> Select "PI" regexp "^ (pi) *$"; --1 (indicates a match)
mysql> Select "Pip" regexp "^ (pi) *$"; -0 (indicates mismatch)
mysql> Select "Pipi" regexp "^ (pi) *$"; --1 (indicates a match)
{1}
{2,3}
This is a more comprehensive approach that enables the functionality of several previous reserved words
A *
Can be written as a{0,}
A +
Can be written as A{1,}
A?
can be written a{0,1}
There is only one integer parameter I within {}, indicates that the character can only appear I times, in {} There is an integer parameter I, followed by a ",", indicating that the character can appear I or more than one time, in {} There is only an integer parameter I, followed by a "," followed by an integer parameter J, indicating that the character can only appear more than I, The following J times (including I and J times). The integral type parameter must be greater than or equal to 0, less than or equal to Re_dup_max (default is 255). If there are two parameters, the second must be greater than or equal to the first
[A-DX]
Matches "A", "B", "C", "D" or "X"
[^A-DX]
Matches any character except "A", "B", "C", "D", "X". "[", "]" must be used in pairs
mysql> Select "AxBC" RegExp "[a-dxyz]"; --1 (indicates a match)
mysql> Select "AxBC" RegExp "^[a-dxyz]$"; -0 (indicates mismatch)
mysql> Select "AxBC" RegExp "^[a-dxyz]+$"; --1 (indicates a match)
mysql> Select "AxBC" RegExp "^[^a-dxyz]+$"; -0 (indicates mismatch)
mysql> Select "Gheis" RegExp "^[^a-dxyz]+$"; --1 (indicates a match)
mysql> Select "Gheisa" RegExp "^[^a-dxyz]+$"; -0 (indicates mismatch)
------------------------------------------------------------
[[. characters.]]
Represents the order in which elements are compared. The order of the characters within the parentheses is unique. But the parentheses can contain wildcards, so he can match more characters. For example: regular expression [[. Ch.]] *c matches the first five characters of a CHCHCC.
[=character_class=]
A class that represents equality, which can be substituted for other equal elements in the class, including itself. For example, if O and (+) are members of an equal class, then [[=o=], [[= (+) =]], and [O (+)] are exactly equivalent.
[: Character_class:]
Inside the parentheses, the name of the character class in the middle of [: and:] can represent all the characters belonging to this class.
The names of the character classes are: alnum, digit, punct, alpha, graph, space, blank, lower, upper, cntrl, print, and Xdigit
mysql> Select "Justalnums" RegExp "[[: alnum:]]+"; --1 (indicates a match)
Mysql> select "!" RegExp "[[: alnum:]]+"; -0 (indicates mismatch)
[[::]]
Match an empty string with the beginning and end of a word, and neither the beginning nor the end of the word is a character that is contained in the alnum and cannot be underlined.
Mysql> Select "A word a" regexp "[[::]]"; --1 (indicates a match)
Mysql> Select "A Xword a" regexp "[[::]]"; -0 (indicates mismatch)
Mysql> Select "Weeknights" RegExp "^ (Wee|week) (knights|nights) $"; --1 (indicates a match)

http://www.bkjia.com/PHPjc/319346.html www.bkjia.com true http://www.bkjia.com/PHPjc/319346.html techarticle A regular expression defines a rule for a string. The simplest regular expression does not contain any reserved words. For example, the regular expression hello only matches the string "Hello". The general positive ...

  • 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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.