Created
February 21, 2015 01:34
-
-
Save claymcleod/a30752456fbb5efe8bcf to your computer and use it in GitHub Desktop.
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
# Title: Regular Expressions with Python | |
# Authors: Clay McLeod | |
# Description: Shows you how to find all instances of a regular expression | |
# in a string | |
# Section: Python | |
# Subsection: General | |
# | |
# Python docs on Regex: https://docs.python.org/2/howto/regex.html | |
# | |
# Notes: | |
# | |
# 1) raw strings have an 'r' prepending the string. They do not process special | |
# characters | |
# 2) regex matching methods: | |
# a) match() - looks at the beginning of the string only | |
# b) search() - looks anywhere in the string for a match | |
# c) findall() - returns all instances of the matches in list form | |
import re | |
raw_string = r'[A-Za-z]atch' | |
compiled_regex = re.compile(raw_string) | |
for token in compiled_regex.findall("Catch the match flying down the hatch"): | |
print "Token %s" % token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment