Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 6th, 2010  |  syntax: Python  |  size: 0.45 KB  |  views: 45  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data