Advertisement
Guest User

Untitled

a guest
Nov 6th, 2010
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement