MySQL Tutorial/String Functions/REGEXP

Материал из SQL эксперт
Версия от 09:49, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

expr REGEXP pat, expr RLIKE pat: Performs a pattern match of expr against pat

Returns 1 if expr matches pat; otherwise it returns 0.

If either expr or pat is NULL, the result is NULL.

REGEXP is not case sensitive, except when used with binary strings.

RLIKE is a synonym for REGEXP.



mysql>
mysql>
mysql> SELECT "ABCDEF" REGEXP "A%C%%";
+-------------------------+
| "ABCDEF" REGEXP "A%C%%" |
+-------------------------+
|                       0 |
+-------------------------+
1 row in set (0.00 sec)
mysql> SELECT "ABCDE" REGEXP ".*";
+---------------------+
| "ABCDE" REGEXP ".*" |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)
mysql> SELECT "new*\n*line" REGEXP "new\\*.\\*line";
+---------------------------------------+
| "new*\n*line" REGEXP "new\\*.\\*line" |
+---------------------------------------+
|                                     1 |
+---------------------------------------+
1 row in set (0.00 sec)
mysql>


SELECT "a" REGEXP "A", "a" REGEXP BINARY "A";

mysql>
mysql> SELECT "a" REGEXP "^[a-d]";
+---------------------+
| "a" REGEXP "^[a-d]" |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)
mysql>