programming-examples/python/Regular_Expression/Search some literals strings in a string.py
2019-11-15 12:59:38 +01:00

9 lines
311 B
Python

import re
patterns = [ 'fox', 'dog', 'horse' ]
text = 'The quick brown fox jumps over the lazy dog.'
for pattern in patterns:
print('Searching for "%s" in "%s" ->' % (pattern, text),)
if re.search(pattern, text):
print('Matched!')
else:
print('Not Matched!')