Skip to content

Instantly share code, notes, and snippets.

@danslimmon
Created January 17, 2014 15:20
Show Gist options
  • Save danslimmon/8475146 to your computer and use it in GitHub Desktop.
Save danslimmon/8475146 to your computer and use it in GitHub Desktop.
You've got to make him/Regular express himself
Python 2.7.4 (default, Jul 7 2013, 10:52:14)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.search("^([Hh]ey ?){4}$", "Hey hey hey hey") is not None
True
>>> re.search("^([Hh]ey ?){4}$", "Hey hey hey hey ") is not None
True
>>> re.search("^([Hh]ey ?){4}$", "Hey hey hey hey ") is not None
False
Now if you remove the ^ and $, anything goes:
>>> re.search("([Hh]ey ?){4}", "whatever Hey hey hey hey fhghwgads") is not None
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment