使用Regex在MySQL中查找包含az,AZ和0-9的字符串

要查找包含az,AZ和0-9的字符串,请使用BINARY REGEXP和AND运算符。

让我们首先创建一个表-

mysql> create table DemoTable738 (UserId varchar(100));

使用插入命令在表中插入一些记录-

mysql> insert into DemoTable738 values('John');
mysql> insert into DemoTable738 values('sAm456');
mysql> insert into DemoTable738 values('98Carol');
mysql> insert into DemoTable738 values('67david');
mysql> insert into DemoTable738 values('69MIKE');

使用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)