#NEWLINE# def Substitute( pattern , repl , text ) : #NEWLINE# #INDENT# "Substitute all 'pattern' in 'text' with 'repl'.\n\n  Args:\n    pattern: string. Pattern to be replaced.\n    repl: string. Replacement pattern.\n    text: string. Text to search.\n  Returns:\n    A string after replacing all patterns with repl.\n  Raises:\n    NoMatchError: when 'pattern' isn't found in string.\n  " #NEWLINE# if ( not re . search ( pattern , text ) ) : #NEWLINE# #INDENT# raise NoMatchError ( 'No match for pattern "{0}" in "{1}"' . format ( pattern , text ) ) #NEWLINE# #UNINDENT# return re . sub ( pattern , repl , text )