Knowledge Point nine: using regular expressions in MySQL (44)
(1): REGEXP ' matching method ':
(2): Common matching method:
Pattern character |
|
^ |
Matches the starting part of the character |
$ |
Matches the part of the end of the string |
. |
Represents any of the characters in a string, including carriage returns and line breaks |
[Character Set and] |
Match character set and any one of the characters in |
[^ Character Set and] |
Match any one character except the character set |
s1| s2| S3 |
Match any string in S1,S2,S3 |
* |
Represents 0 and one or more of its preceding characters |
+ |
Represents 1 or more characters in front of it |
String{n} |
String appears n times |
string {m,n} |
The string appears at least m times and appears at most n times |
1 --^ matches the starting part of the character2 --querying users with a user name starting with T3 SELECT * fromCms_userWHEREUsername REGEXP'^t';4 5 --$ matches the part of the end of the string6 7 SELECT * fromCms_userWHEREUsername REGEXP'g$';8 9 Ten --. Represents any character One A SELECT * fromCms_userWHEREUsername REGEXP'.'; - - SELECT * fromCms_userWHEREUsername REGEXP'R.. G'; the - SELECT * fromCms_userWHEREUsername like 'R__g'; - - --[Set] [LTO] + - SELECT * fromCms_userWHEREUsername REGEXP'[LTO]'; + A --[^ charset] In addition to the contents of the character set at SELECT * fromCms_userWHEREUsername REGEXP'[^lto]'; - - SELECT * fromCms_userWHEREUsername REGEXP'[^l]'; - - INSERTCms_user (username,password,regtime,proid) - VALUES('lll','lll',138212349,2), in('TTT','lll',138212349,2), -('ooo','lll',138212349,2); to + SELECT * fromCms_userWHEREUsername REGEXP'[A-k]'; - the SELECT * fromCms_userWHEREUsername REGEXP'[^a-m]'; * $ SELECT * fromCms_userWHEREUsername REGEXP'Ng|qu';Panax Notoginseng - SELECT * fromCms_userWHEREUsername REGEXP'Ng|qu|te'; the + SELECT * fromCms_userWHEREUsername REGEXP'que*'; A the + SELECT * fromCms_userWHEREUsername REGEXP't+'; - $ SELECT * fromCms_userWHEREUsername REGEXP'que+'; $ - SELECT * fromCms_userWHEREUsername REGEXP'que{2}'; - the SELECT * fromCms_userWHEREUsername REGEXP'Que{3}'; - Wuyi SELECT * fromCms_userWHEREUsername REGEXP'que{1,3}';
regular-expression testing
MySQL Beginner note Seven: Use regular expressions in MySQL! (Video serial number: primary _44)