用于查找包含 N 个分号的行
我们首先创建一个表 -
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY , Title text ); Query OK, 0 rows affected (0.88 sec)
使用 insert 命令向表中插入一些记录 -
mysql> insert into DemoTable(Title) values('This is; a; MySQL;Tutorial'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Title) values('Java is; an;Object Oriented'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Title) values('MongoDB ; is;a; database'); Query OK, 1 row affected (0.12 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
这将产生以下输出 -
+----+-----------------------------+ | Id | Title | +----+-----------------------------+ | 1 | This is; a; MySQL;Tutorial | | 2 | Java is; an;Object Oriented | | 3 | MongoDB ; is;a; database | +----+-----------------------------+ 3 rows in set (0.00 sec)
以下正则表达式可用于查找包含 3 个分号的行 -
mysql> select *from DemoTable where Title REGEXP '(.*;){3}';
这将产生以下输出 -
+----+----------------------------+ | Id | Title | +----+----------------------------+ | 1 | This is; a; MySQL;Tutorial | | 3 | MongoDB ; is;a; database | +----+----------------------------+ 2 rows in set (0.00 sec)
广告