def chain_sub_regexes(phrase, *regex_sub_pairs):
for regex, substitution in regex_sub_pairs:<EOL><INDENT>if isinstance(regex, basestring):<EOL><INDENT>regex = re.compile(regex)<EOL><DEDENT>phrase = regex.sub(substitution, phrase)<EOL><DEDENT>return phrase<EOL>
Allow for a series of regex substitutions to occur

chain_sub_regexes('test ok', (' ', '_'), ('k$', 'oo'))
# => 'test_ooo'