match() in regular expression in python by R4R Team

- match() in a regular expression are used to match the pattern to the string.

Syntax-

re.match(pattern,string,flag=0)


program-

#import the re module
import re

#Given string is
s = "This is programming language"

x=re.match('This',s)
if x:
print("Matched")
else:
print("Not matched")


x=re.match('The',s)
if x:
print("Matched")
else:
print("Not matched")


output-

Matched
Not matched


-In this program, we have a string "This is programming language" then we match the pattern to the string, if the pattern is matched then we print in if condition otherwise in else condition.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!