MySQL criterion the description of expression
Tuesday, March 03, 2009 by rain
A simple data is here,Its oversight a few detailed information.
criterion the regulation that expression defined a string.The simplest criterion expression does not contain any key word.For example,criterion expression Hello is mixed only string " Hello " match.
General criterion expression used certain and special structure,So it can match more string.For example,criterion expression Hello | Word can match string already " Hello " also can match string " Word " .Lift more complex the one example of the dot,criterion expression B[an]*s can match string " Bananas " , " Baaaaas " , " Bs " hold the post of with etc why B begin with the string of S ending,Random can include among A and aleatoric a combination of N.
One is using the following key word in expression
^
After the string that matchs the string begin of the face
Mysql%26gt;Select "fonfo" REGEXP "^fo$"; -%26gt;0 (express not to match)
Mysql%26gt;Select "fofo" REGEXP "^fo"; -%26gt;1 (express to match)
$
The string of the face is terminal before the string that matchs
Mysql%26gt;Select "fono" REGEXP "^fono$"; -%26gt;1 (express to match)
Mysql%26gt;Select "fono" REGEXP "^fo$"; -%26gt;0 (express not to match)
.
Match any character (include new travel)
Mysql%26gt;Select "fofo" REGEXP "^f. *"; -%26gt;1 (express to match)
Mysql%26gt;Select "fonfo" REGEXP "^f. *"; -%26gt;1 (express to match)
A*
Match random many A (include null string)
Mysql%26gt;Select "Ban" REGEXP "^Ba*n"; -%26gt;1 (express to match)
Mysql%26gt;Select "Baaan" REGEXP "^Ba*n"; -%26gt;1 (express to match)
Mysql%26gt;Select "Bn" REGEXP "^Ba*n"; -%26gt;1 (express to match)
A+
Match random many A (do not include null string)
Mysql%26gt;Select "Ban" REGEXP "^Ba+n"; -%26gt;1 (express to match)
Mysql%26gt;Select "Bn" REGEXP "^Ba+n"; -%26gt;0 (express not to match)
A?
Match or zero A
Mysql%26gt;Select "Bn" REGEXP "^Ba? N"; -%26gt;1 (express to match)
Mysql%26gt;Select "Ban" REGEXP "^Ba? N"; -%26gt;1 (express to match)
Mysql%26gt;Select "Baan" REGEXP "^Ba? N"; -%26gt;0 (express not to match)
De | Abc
Match De or Abc
Mysql%26gt;Select "pi" REGEXP "pi | Apa"; -%26gt;1 (express to match)
Mysql%26gt;Select "axe" REGEXP "pi | Apa"; -%26gt;0 (express not to match)
Mysql%26gt;Select "apa" REGEXP "pi | Apa"; -%26gt;1 (express to match)
Mysql%26gt;Select "apa" REGEXP "^(pi | Apa)$"; -%26gt;1 (express to match)
Mysql%26gt;Select "pi" REGEXP "^(pi | Apa)$"; -%26gt;1 (express to match)
Mysql%26gt;Select "pix" REGEXP "^(pi | Apa)$"; -%26gt;0 (express not to match)
(Abc)*
Match random many Abc (include null string)
Mysql%26gt;Select "pi" REGEXP "^(pi)*$"; -%26gt;1 (express to match)
Mysql%26gt;Select "pip" REGEXP "^(pi)*$"; -%26gt;0 (express not to match)
Mysql%26gt;Select "pipi" REGEXP "^(pi)*$"; -%26gt;1 (express to match)
{1}
{2, 3}
This is a more comprehensive method,It can come true in front the function of several kinds of key word
A*
Can write into A{0, }
A+
Can write into A{1, }
A?
Can write into A{0, 1}
Only inside {} one is rectified model parameter I,State character can appear only I second;There is to rectify inside {} model parameter I,One follows from the back " ," ,State character can appear I second or I second above;Only inside {} one is rectified model parameter I,One follows from the back " ," ,Rectify with again model parameter J, state character can appear only I second above,J second the following (include I second with J second) .Among them whole model parameter must is more than be equal to 0,Be less than be equal to RE_DUP_MAX (acquiesce is 255) .If have two parameter,The second must is more than be equal to the first
[A-dX]
Match " A " , " B " , " C " , " D " or " X "
[^a-dX]
Match except " A " , " B " , " C " , " D " , " X " any character beyond." [" , " ] " must use in couples
Mysql%26gt;Select "aXbc" REGEXP "[a-dXYZ]"; -%26gt;1 (express to match)
Mysql%26gt;Select "aXbc" REGEXP "^[a-dXYZ]$"; -%26gt;0 (express not to match)
Mysql%26gt;Select "aXbc" REGEXP "^[a-dXYZ]+$"; -%26gt;1 (express to match)
Mysql%26gt;Select "aXbc" REGEXP "^[^a-dXYZ]+$"; -%26gt;0 (express not to match)
Mysql%26gt;Select "gheis" REGEXP "^[^a-dXYZ]+$"; -%26gt;1 (express to match)
Mysql%26gt;Select "gheisa" REGEXP "^[^a-dXYZ]+$"; -%26gt;0 (express not to match)
------------------------------------------------------------
[[.characters. ] ]
The order that expresses to compare an element.The character order inside bracket is exclusive.But can include in bracket match accord with, so he can match more character.E.g. :criterion expression [[.ch. ] ] before five character that *c matchs Chchcc.
[=character_class= ]
Express equal kind,Can replace kind in other and equal element,Include itself.For example,If O is mixed (+ ) be equal kind member,So [[=o=]] , [[=(+)=]] and [O(+)] is completely equivalent.
[: CHaracter_class:]
Inside bracket,Be in [: ?: ] among it is character kind name,Can represent belong to this kind all character.
Character kind the name has: Alnum, Digit, Punct, Alpha, Graph, Space, Blank, Lower, Upper, Cntrl, Print and Xdigit
Mysql%26gt;Select "justalnums" REGEXP "[[:aLnum:] ] + "; -%26gt;1 (express to match)
Mysql%26gt;Select " ! ! "REGEXP "[[:aLnum:] ] + "; -%26gt;0 (express not to match)
[[: ] ]
The string that matchs begin of a word and terminal sky respectively,This word begin and ending are not including the character in Alnum also cannot be underline.
Mysql%26gt;Select "a Word A" REGEXP "[[: ] ] "; -%26gt;1 (express to match)
Mysql%26gt;Select "a Xword A" REGEXP "[[: ] ] "; -%26gt;0 (express not to match)
Mysql%26gt;Select "weeknights" REGEXP "^(wee | Week)(knights | Nights)$"; -%26gt;1 (express to match)