- Match one of several characters
Just want to match a specific character. You can do this by specifying a set [
]
of characters that are enclosed and used.
[456]
Defines a set of characters that he means to match 4 or 5 or 6. []
is another form of an or statement. [456]
is [4|5|6]
the abbreviation.
- Match Range
[1-3]
are a-z
legal in scope,
Match Special characters
The regular expression language is composed of special characters with special meanings.
.
Matches any one character in a regular expression
For example, matches on
a line that includes a string in Prod_name:
How does that match,, .
[]
|
, -
?
In order to match Special characters, it must be used \\
as leading. For example, to \\.
find·
Match character class
Match multiple instances
Another example is a matching 4-digit number:
sticks?
: s
after ?
making s optional, because ?
it matches 0 or 1 occurrences of any character immediately preceding it.
[:digit:]
Matches any number, thus it is a set of numbers. {4}
the character that precedes it is exactly required to appear 4 times.
So [:digit:]{4}
match any 4-bit numbers that are connected together.
Locator characters
All the examples so far have been matched to any text in a string so far. To match a specific text, you need to use a locator.
You can also test the correctness of regular expressions without using a database:
SELECT to test the regular expression, the RegExp check always returns 0 or 1,
SELECT ' HELLO ' REGEXP ' 0 '//return to 0
MySQL must know reading notes the Nineth chapter uses regular expressions to filter data