Regular Expressions
900
Warning
The
REGEXP
[899]
and
RLIKE
[899]
operators work in byte-wise fashion,
so they are not multi-byte safe and may produce unexpected results with
multi-byte character sets. In addition, these operators compare characters by
their byte values and accented characters may not compare as equal even if
a given collation treats them as equal.
A regular expression describes a set of strings. The simplest regular expression is one that has no
special characters in it. For example, the regular expression
hello
matches
hello
and nothing else.
Nontrivial regular expressions use certain special constructs so that they can match more than one
string. For example, the regular expression
hello|word
matches either the string
hello
or the string
word
.
As a more complex example, the regular expression
B[an]*s
matches any of the strings
Bananas
,
Baaaaas
,
Bs
, and any other string starting with a
B
, ending with an
s
, and containing any number of
a
or
n
characters in between.
A regular expression for the
REGEXP
[899]
operator may use any of the following special characters
and constructs:
•
^
Match the beginning of a string.
mysql>
SELECT 'fo\nfo' REGEXP '^fo$';
-> 0
mysql>
SELECT 'fofo' REGEXP '^fo';
-> 1
•
$
Match the end of a string.
mysql>
SELECT 'fo\no' REGEXP '^fo\no$';
-> 1
mysql>
SELECT 'fo\no' REGEXP '^fo$';
-> 0
•
.
Match any character (including carriage return and newline).
mysql>
SELECT 'fofo' REGEXP '^f.*$';
-> 1
mysql>
SELECT 'fo\r\nfo' REGEXP '^f.*$';
-> 1
•
a*
Match any sequence of zero or more
a
characters.
mysql>
SELECT 'Ban' REGEXP '^Ba*n';
-> 1
mysql>
SELECT 'Baaan' REGEXP '^Ba*n';
-> 1
mysql>
SELECT 'Bn' REGEXP '^Ba*n';
-> 1
•
a+
Match any sequence of one or more
a
characters.
mysql>
SELECT 'Ban' REGEXP '^Ba+n';
-> 1
mysql>
SELECT 'Bn' REGEXP '^Ba+n';
-> 0
•
a?
Match either zero or one
a
character.
mysql>
SELECT 'Bn' REGEXP '^Ba?n';
-> 1
mysql>
SELECT 'Ban' REGEXP '^Ba?n';
-> 1
mysql>
SELECT 'Baan' REGEXP '^Ba?n';
-> 0
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...