Regular Expressions
901
•
de|abc
Match either of the sequences
de
or
abc
.
mysql>
SELECT 'pi' REGEXP 'pi|apa';
-> 1
mysql>
SELECT 'axe' REGEXP 'pi|apa';
-> 0
mysql>
SELECT 'apa' REGEXP 'pi|apa';
-> 1
mysql>
SELECT 'apa' REGEXP '^(pi|apa)$';
-> 1
mysql>
SELECT 'pi' REGEXP '^(pi|apa)$';
-> 1
mysql>
SELECT 'pix' REGEXP '^(pi|apa)$';
-> 0
•
(abc)*
Match zero or more instances of the sequence
abc
.
mysql>
SELECT 'pi' REGEXP '^(pi)*$';
-> 1
mysql>
SELECT 'pip' REGEXP '^(pi)*$';
-> 0
mysql>
SELECT 'pipi' REGEXP '^(pi)*$';
-> 1
•
{1}
,
{2,3}
{n}
or
{m,n}
notation provides a more general way of writing regular expressions that match many
occurrences of the previous atom (or “piece”) of the pattern.
m
and
n
are integers.
•
a*
Can be written as
a{0,}
.
•
a+
Can be written as
a{1,}
.
•
a?
Can be written as
a{0,1}
.
To be more precise,
a{n}
matches exactly
n
instances of
a
.
a{n,}
matches
n
or more instances of
a
.
a{m,n}
matches
m
through
n
instances of
a
, inclusive.
m
and
n
must be in the range from
0
to
RE_DUP_MAX
(default 255), inclusive. If both
m
and
n
are
given,
m
must be less than or equal to
n
.
mysql>
SELECT 'abcde' REGEXP 'a[bcd]{2}e';
-> 0
mysql>
SELECT 'abcde' REGEXP 'a[bcd]{3}e';
-> 1
mysql>
SELECT 'abcde' REGEXP 'a[bcd]{1,10}e';
-> 1
•
[a-dX]
,
[^a-dX]
Matches any character that is (or is not, if ^ is used) either
a
,
b
,
c
,
d
or
X
. A
-
character between two
other characters forms a range that matches all characters from the first character to the second.
For example,
[0-9]
matches any decimal digit. To include a literal
]
character, it must immediately
follow the opening bracket
[
. To include a literal
-
character, it must be written first or last. Any
character that does not have a defined special meaning inside a
[]
pair matches only itself.
mysql>
SELECT 'aXbc' REGEXP '[a-dXYZ]';
-> 1
mysql>
SELECT 'aXbc' REGEXP '^[a-dXYZ]$';
-> 0
mysql>
SELECT 'aXbc' REGEXP '^[a-dXYZ]+$';
-> 1
mysql>
SELECT 'aXbc' REGEXP '^[^a-dXYZ]+$';
-> 0
mysql>
SELECT 'gheis' REGEXP '^[^a-dXYZ]+$';
-> 1
mysql>
SELECT 'gheisa' REGEXP '^[^a-dXYZ]+$';
-> 0
•
[.characters.]
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...