Thursday, May 2, 2024

BCA PART B 1. Demonstrate usage of basic regular expression

 


import re
print("Usage of square bracket : ")
string = "The quick brown fox jumps over the lazy dog"
pattern = "[a-m]"
result = re.findall(pattern, string)
print(result)

pattern = r"^The"
print("\n\n Search the pattern "+pattern+" at the end of the string ")
match = re.search(pattern, string)
if match:
print("Match found!")
else:
print("Match not found.")

No comments:

Post a Comment