Last active
February 5, 2016 12:52
-
-
Save metaodi/3116956fef7d4a7bc80a to your computer and use it in GitHub Desktop.
Python Summit 2016
This file contains hidden or 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
# Named regex groups | |
import re | |
sentence = "\"The Hitchhiker's Guide to the Galaxy\" was published in 1979" | |
regex = "\"([\w ']+)\" was published in (\S+)" | |
print "find_all: %s"%(re.findall(regex, sentence)) | |
match = re.search("\"(?P<book>[\w ']+)\" was published in (?P<year>\S+)", sentence) | |
print "match groups: %s"%(str(match.groups())) | |
print "match group1: %s"%(str(match.group(1))) | |
print "match group1 span: %s"%(str(match.span(1))) | |
print "match groupdict: %s"%(str(match.groupdict())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment