在MySQL中使用正則表示式查詢包含a-z、A-Z和0-9的字串
要查詢包含a-z、A-Z和0-9的字串,請使用BINARY REGEXP以及AND運算子。
讓我們先建立一個表:
mysql> create table DemoTable738 (UserId varchar(100)); Query OK, 0 rows affected (0.81 sec)
使用insert命令在表中插入一些記錄:
mysql> insert into DemoTable738 values('John');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable738 values('sAm456');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable738 values('98Carol');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable738 values('67david');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable738 values('69MIKE');
Query OK, 1 row affected (0.18 sec)使用select語句顯示錶中的所有記錄:
mysql> select *from DemoTable738;
這將產生以下輸出:
+---------+ | UserId | +---------+ | John | | sAm456 | | 98Carol | | 67david | | 69MIKE | +---------+ 5 rows in set (0.00 sec)
以下是使用REGEXP查詢字串的查詢:
mysql> select *from DemoTable738 where UserId REGEXP BINARY '[A-Z]' and UserId REGEXP BINARY '[a-z]' and UserId REGEXP BINARY '[0-9]';
這將產生以下輸出:
+---------+ | UserId | +---------+ | sAm456 | | 98Carol | +---------+ 2 rows in set (0.03 sec)
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP