Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Python Regular Expression

 

In this lecture we will see that,

How to implement patterns with match and search functions with Regular expression ?

 

When myString matches with Pattern :

import re

pattern=r"^abc"

myString="abcdef"

print(re.match(pattern,myString))

Output :

<_sre.SRE_Match object; span=(0,3), match='abc'>

 

When myString doesn’t match with Pattern :

import re

pattern=r"^abc"

myString="abdef"

print(re.match(pattern,myString))

Output :

None

 

When email matches with Pattern :

import re

pattern=r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"

email="abc@gmail.com"

print (re.match(pattern,email))

Output :

<_sre.SRE_Match object; span=(0,13), match='abc@gmail.com'>

 

When email doesn’t matches with Pattern :

import re

pattern=r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"

email="abcgmail.com"

print (re.match(pattern,email))

Output :

None

 

So this is how you can make any pattern of your own requirement and match it.

FAQs

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere