The performance of the normal expression in MySQL is higher than like, so here is a summary of the use of regular expressions.
Patterns of regular expressions and their meanings:
The following examples illustrate their usage:
Build Table Student:
CREATE TABLE student (ID int (6) Auto_increment,name Carchar (6), age int (3), primary key (ID)); Insert data: INSERT into student (name , age) VALUES (' Xzb ', (), (' Spal '), (' WGC ', 32);
1.^
Select name from student where name REGEXP ' ^x '; --querying data that begins with X
2.$
SELECT * FROM student where name REGEXP ' C $ '; --Query for data ending in C
3. ".": This character is the English point, it matches any one character, including carriage return, line wrapping and so on.
SELECT * FROM student where name REGEXP ' X. '; --Match the first letter X, the rest of the letter arbitrary data
4.*: An asterisk matches 0 or more characters and must have content before it.
SELECT * FROM student where name REGEXP ' x* '; --match any of the characters
5. "+": the plus sign matches 1 or more characters, and must have content before it.
SELECT * FROM student where name REGEXP ' x* ';--matches any character greater than 1
6. "?": the question mark matches 0 or 1 times.
SELECT * FROM student where name REGEXP ' x? '; --Match 0 or 1 characters
7.xzb|spal|
SELECT * FROM student where name REGEXP ' Xzb|spal ';--match xzb or Spal
8.[x-z]*
SELECT * FROM student where name REGEXP ' ^[x-z] ';--matches data that begins with a character in X, Y, Z
SELECT * FROM student where name REGEXP ' [a-d]$ ';--match data ending with characters in a-d
9.[^x-z]*
SELECT * FROM student where name REGEXP ' ^[^x-z] ';--matches data that does not begin with a character that is not in the X-z
SELECT * FROM student where name REGEXP ' [^h-j]$ ';--matches data that is not at the beginning of a character in X-z
10.{n}
SELECT * FROM student where name REGEXP ' ^s{2} ';--match all data that starts with S and repeats at least 2 times
11.{N,M}
SELECT * FROM student where name REGEXP ' ^s{2,5} ';--match all data that starts with S and repeats 2 to 5 times
The use of the MySQL Express expression