Table 12.9 String Regular Expression Operators
A regular expression is a powerful way of specifying a pattern for a complex search.
MySQL uses Henry Spencer’s implementation of regular expressions, which is aimed at conformance with POSIX 1003.2. MySQL uses the extended version to
support pattern-matching operations performed with the
REGEXP operator in SQL statements.
This section summarizes, with examples, the special characters and constructs that can be used in MySQL for
REGEXP operations. It does not contain all the details that can be found in Henry Spencer’s
Because MySQL uses the C escape syntax in strings (for example, “
\n” to represent the newline character), you must double any “
\” that you use in your
使用 （NOT）REGEXP 运算符。
mysql> SELECT 'Monty!' REGEXP '.*'; -> 1 mysql> SELECT 'new*\n*line' REGEXP 'new\\*.\\*line'; -> 1 mysql> SELECT 'a' REGEXP 'A', 'a' REGEXP BINARY 'A'; -> 1 0 mysql> SELECT 'a' REGEXP '^[a-d]'; -> 1