Return a specific MySQL string using regular expressions



Let us first create a table −

mysql> create table DemoTable649 (Value text); Query OK, 0 rows affected (0.68 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable649 values('1903'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable649 values('9321010'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable649 values('983032023393'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable649 values('1234567892'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable649 values('989898989'); Query OK, 1 row affected (0.20 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable649;

This will produce the following output −

+--------------+ | Value       | +--------------+ | 1903       | | 9321010    | | 983032023393 | | 1234567892 | | 989898989 | +--------------+ 5 rows in set (0.00 sec)

Following is the query to return a specific MySQL string using regex −

mysql> select *from DemoTable649 where Value REGEXP '[0-9]{11}';

This will produce the following output −

+--------------+ | Value       | +--------------+ | 983032023393 | +--------------+ 1 row in set (0.00 sec)
Updated on: 2019-08-23T11:17:13+05:30

141 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements