- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Select all email addresses beginning with 5 numeric characters (regular expression) in MySQL
To get the email addresses beginning with 5 numeric characters, the optional solution is to use REGEXP −
select *from yourTableName where yourColumnName regexp "^[0-9]{5}";
Let us first create a table −
mysql> create table DemoTable ( UserEmailAddress varchar(100) ); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('6574John@gmail.com'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Carol23456@gmail.com'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('98989Chris_45678@gmail.com'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Mike12@gmail.com'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values('56453Adam@gmail.com'); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------------------------+ | UserEmailAddress | +----------------------------+ | 6574John@gmail.com | | Carol23456@gmail.com | | 98989Chris_45678@gmail.com | | Mike12@gmail.com | | 56453Adam@gmail.com | +----------------------------+ 5 rows in set (0.00 sec)
Following is the query to select all email addresses beginning with 5 numeric characters −
mysql> select *from DemoTable where UserEmailAddress regexp "^[0-9]{5}";
This will produce the following output −
+----------------------------+ | UserEmailAddress | +----------------------------+ | 98989Chris_45678@gmail.com | | 56453Adam@gmail.com | +----------------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Select query with regular expression in MySQL
- Extracting email addresses using regular expressions in Python
- How to mask user email addresses with a different domain in MySQL?
- MySQL query to select all fields beginning with a given number with next character a letter?
- How to select records beginning with certain numbers in MySQL?
- How to print all the characters of a string using regular expression in Java?
- Write a Regular Expression to remove all special characters from a JavaScript String?
- How to validate an email id using regular expression in Python?
- MySQL regular expression to update a table with column values including string, numbers and special characters
- How to use special characters in Python Regular Expression?
- How to select everything before @ in an email-id with in MySQL?
- How to extract email id from text using Python regular expression?
- How to match at the beginning of string in python using Regular Expression?
- How to select all the characters after the first 20 characters from a column in MySQL?
- Regular Expression in Python with Examples?

Advertisements