Created
January 17, 2014 15:20
-
-
Save danslimmon/8475146 to your computer and use it in GitHub Desktop.
You've got to make him/Regular express himself
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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