MySQL Tutorial/Regular Expressions/Not
Версия от 13:44, 26 мая 2010; (обсуждение)
Содержание
- 1 Matches any character that is (or is not, if ^ is used) either a, b, c, d or X: [a-dX], [^a-dX]
- 2 SELECT "abcda" REGEXP "^[^a-dXYZ]+$";
- 3 SELECT "abcdeX" REGEXP "^[^a-dXYZ]+$";
- 4 SELECT "aXbc" REGEXP "^[a-dXYZ]$";
- 5 SELECT "aXbc" REGEXP "^[a-dXYZ]+$"; (2)
- 6 SELECT "aXbc" REGEXP "^[^a-dXYZ]+$"; (3)
Matches any character that is (or is not, if ^ is used) either a, b, c, d or X: [a-dX], [^a-dX]
A character between two other characters forms a range.
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>
mysql> SELECT "aXbc" REGEXP "[a-dXYZ]";
+--------------------------+
| "aXbc" REGEXP "[a-dXYZ]" |
+--------------------------+
| 1 |
+--------------------------+
1 row in set (0.00 sec)
SELECT "abcda" REGEXP "^[^a-dXYZ]+$";
mysql>
mysql>
mysql> SELECT "abcda" REGEXP "^[^a-dXYZ]+$";
+-------------------------------+
| "abcda" REGEXP "^[^a-dXYZ]+$" |
+-------------------------------+
| 0 |
+-------------------------------+
1 row in set (0.00 sec)
mysql>
SELECT "abcdeX" REGEXP "^[^a-dXYZ]+$";
mysql>
mysql> SELECT "abcdeX" REGEXP "^[^a-dXYZ]+$";
+--------------------------------+
| "abcdeX" REGEXP "^[^a-dXYZ]+$" |
+--------------------------------+
| 0 |
+--------------------------------+
1 row in set (0.00 sec)
mysql>
SELECT "aXbc" REGEXP "^[a-dXYZ]$";
mysql>
mysql>
mysql> SELECT "aXbc" REGEXP "^[a-dXYZ]$";
+----------------------------+
| "aXbc" REGEXP "^[a-dXYZ]$" |
+----------------------------+
| 0 |
+----------------------------+
1 row in set (0.00 sec)
SELECT "aXbc" REGEXP "^[a-dXYZ]+$"; (2)
mysql>
mysql>
mysql>
mysql> SELECT "aXbc" REGEXP "^[a-dXYZ]+$";
+-----------------------------+
| "aXbc" REGEXP "^[a-dXYZ]+$" |
+-----------------------------+
| 1 |
+-----------------------------+
1 row in set (0.00 sec)
SELECT "aXbc" REGEXP "^[^a-dXYZ]+$"; (3)
mysql>
mysql>
mysql> SELECT "aXbc" REGEXP "^[^a-dXYZ]+$";
+------------------------------+
| "aXbc" REGEXP "^[^a-dXYZ]+$" |
+------------------------------+
| 0 |
+------------------------------+
1 row in set (0.02 sec)