Practical Unix: Regular Expressions 6 - Python
Channel: Sam King
Date: 2013-12-14

0:10 import re
0:15 re.search(pattern, str) is the equivalent of what we've been doing with grep.
0:51 if there's no match, it returns None, so you can use 'if match:'
1:16 use raw strings for regexes in Python.  Then, a string like r'foo\dbar' will pass on the backslash literally to the regex library.
2:00 match.group(group_number) will extract the text from a group.
2:28 re.sub(pattern, replacement, str) lets you replace pattern with replacement in str.  It returns the replaced string.  The replacement string isn't a regex (eg, wildcards aren't meaningful and aren't supported).  It supports group references like \1, though.
3:43 the python regex documentation is at http://docs.python.org/2/library/re.html