Articles → Python → Or operator in regular expression in python

Or operator in regular expression in python






Purpose





Example


import re


pattern = "^\d|\d$"


text1 = r"sdasdasd345"
text2 = r"111sdasdasd"

print("text1 ends with number:", re.search(pattern, text1))
print("text2 ends with number:", re.search(pattern, text2))



Output


Picture showing output of Or operator in regular expression in python

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, July 09, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250