使用REGEXP匹配每条记录后的可选行尾吗?
让我们首先创建一个表-
mysql> create table DemoTable(EmployeeCode varchar(100));
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('EMPLOYEE:100 John Smith'); mysql> insert into DemoTable values('EMPLOYEE:16537 Chris Brown'); mysql> insert into DemoTable values('EMPLOYEE:100 David Miller'); mysql> insert into DemoTable values('EMPLOYEE:100 23432 David Miller');
使用select语句显示表中的所有记录-
mysql>; select *from DemoTable;
这将产生以下输出-
+---------------------------------+ | EmployeeCode | +---------------------------------+ | EMPLOYEE:100 John Smith | | EMPLOYEE:16537 Chris Brown | | EMPLOYEE:100 David Miller | | EMPLOYEE:100 23432 David Miller | +---------------------------------+ 4 rows in set (0.00 sec)
以下是匹配可选行尾的查询,例如,“EMPLOYEE:10023432DavidMiller”中100之后的23434-
mysql> select *from DemoTable where EmployeeCode REGEXP "EMPLOYEE:100([^0-9]|$)";
这将产生以下输出-
+---------------------------------+ | EmployeeCode | +---------------------------------+ | EMPLOYEE:100 John Smith | | EMPLOYEE:100 David Miller | | EMPLOYEE:100 23432 David Miller | +---------------------------------+ 3 rows in set (0.00 sec)