Write a Python program that matches a word at the end of string, with optional punctuation.
Example :
import re
def match(text):
patterns = ‘\w’
if re.search(patterns, text):
return ‘Found a match!’
else: #\w = letters ( Match alphanumeric character, including “_”)
return(‘Not matched!’)
print(match(“Im studying in EDYODA.”))
print(match(“Im studying in EDYODA.”))
print(match(“Im studying in EDYODA.”))
print(match(“Im studying in EDYODA.”))
OUTPUT :
Found a match!
Found a match!
Found a match!
Found a match!
In above code we are using “\w” identifiers which means "letters ( Match alphanumeric character, including “_”) " . All the print statement contains letters so the condition is satisfied and we are getting the output as found a match