SHARE
TWEET

Untitled

a guest Nov 6th, 2010 49 Never
  1. import re
  2.  
  3. # how one would normally do it
  4. def contains_foobar_1(s):
  5.     return "foobar" in s.lower()
  6.  
  7. # how one does it with regex, properly
  8. def contains_foobar_2(s):
  9.     return re.search(r'foobar', s, flags = re.IGNORECASE) is not None
  10.  
  11. # how one does it with regex
  12. # (trying to squeeze every bit of efficiency outta it)
  13. _foobar_re = re.compile(r'foobar', flags = re.IGNORECASE)
  14. def contains_foobar_3(s):
  15.     return _foobar_re.search(s) is not None
RAW Paste Data
Top