- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding only strings beginning with a number using MySQL Regex?
To find strings beginning with a number, use Regular Expressions. Let us first create a table −
mysql> create table DemoTable ( Id varchar(200) ); Query OK, 0 rows affected (0.59 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values('123User'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('_$123User'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('User123456'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('0000User'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('&^*User'); Query OK, 1 row affected (0.24 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+------------+ | Id | +------------+ | 123User | | _$123User | | User123456 | | 0000User | | &^*User | +------------+ 5 rows in set (0.00 sec)
Here is the query to find strings starting with a number using MySQL Regexp −
mysql> SELECT DISTINCT Id FROM DemoTable WHERE Id REGEXP '^[0-9]';
This will produce the following output −
+----------+ | Id | +----------+ | 123User | | 0000User | +----------+ 2 rows in set (0.58 sec)
Advertisements