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



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

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250