re_search.py 431 B

12345678910111213141516171819202122
  1. #! /usr/bin/env python
  2. # Simple regex examples
  3. import re
  4. foo="The foo in bar falls in Maine, mainly"
  5. if re.search("foo",foo):
  6. print(f"'foo' is in {foo}")
  7. else:
  8. print(f"'foo' is NOT in {foo}")
  9. if re.search("bar",foo):
  10. print(f"'bar' is in {foo}")
  11. else:
  12. print(f"'bar' is NOT in {foo}")
  13. if re.search("^The",foo):
  14. print(f"'The' is at the start of {foo}")
  15. else:
  16. print(f"'The' is NOT at the start of {foo}")