让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY , Title text );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(Title) values('This is; a; MySQL;Tutorial'); mysql> insert into DemoTable(Title) values('Java is; an;Object Oriented'); mysql> insert into DemoTable(Title) values('MongoDB ; is;a; database');
使用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)