InterviewSolution
Saved Bookmarks
| 1. |
Write a Program to match a string that has the letter ‘a’ followed by 4 to 8 'b’s. |
|
Answer» We can USE the re module of python to perform regex pattern COMPARISON here. import redef match_text(txt_data): pattern = 'ab{4,8}' if re.search(pattern, txt_data): #search for pattern in txt_data return 'MATCH found' else: return('Match not found')print(match_text("abc")) #prints Match not foundprint(match_text("aabbbbbc")) #prints Match found |
|