# Python Programs for Most commonly used Regex – 2023

So guys in this blog we will see the Python Programs for most commonly used regex like regex to check mobile phones, regex to check email, and many more. So without any further due, let’s do it…

## What is the regex to check a 10-digit mobile phone?

```# Python Programs for Most commonly used Regex
# Regex to check a 10-digit mobile phone

import re

regex_expression = "[6-9][0-9]{9}"

mobile = input('Enter a mobile number - ')

if len(mobile)==10:
m = re.fullmatch(regex_expression ,mobile)
if m!=None:
print('Valid 10 digit number')
else:
print('Not a valid 10 digit number')
else:
print('Please enter a 10 digit mobile number')```
• The regex says that the number should start from either 6,7,8 or 9.
• And then after that, there should be 9 numbers from the range (0,9).

Output

Enter a mobile number – 9999999999
Valid 10 digit number

Enter a mobile number – 1999999999
Not a valid 10 digit number

Enter a mobile number – 99999
Not a valid 10 digit number

## What is the regex to check valid email?

```# Python Programs for Most commonly used Regex
# Regex to check valid email format

import re

regex_expression = "[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}"

email = input('Enter an email id - ')

e = re.fullmatch(regex_expression ,email)

if e!=None:
print('Valid email')
else:
print('Not a valid email')```

Output

Enter an email id – asharma@gmail.com
Valid email

Enter an email id – ..@gmail.com
Not a valid email

Enter an email id – asharma123@gmail.com
Valid email

## What is the regex to check the date?

```# Python Programs for Most commonly used Regex\
# Regex to check the date

import re

regex_expression = "\d{2}/\d{2}/\d{4}"

date = input('Enter a date - ')

e = re.fullmatch(regex_expression ,date)

if e!=None:
print('Valid date')
else:
print('Not a valid date')```
• The regular expression says that the string should match nn/nn/nnnn where n is a number.
• \d is used to match decimals.

Output

Enter a date – 02/02/2022
Valid date

Enter a date – 02/2/2022
Not a valid date

Enter a date – 2/2/2022
Not a valid date

Do let me know if there’s any query while using the Most commonly used Regex in Python by contacting me via email or LinkedIn.

So this is all for this blog folks, thanks for reading it and I hope you are taking something with you after reading this and till the next time …

Read my previous post: How to get the current date and time in Python

Check out my other machine learning projectsdeep learning projectscomputer vision projectsNLP projects, and Flask projects at machinelearningprojects.net