Further optimization

String mutations replaced with string.joins, removed unnecessary
lambda.
replaced re.match with re.search in output scan

To shorten the amount of work (and clean the code), I replaced
re.match (match from beginning of string) with re.search (match
anywhere in string). The result is I can have one regex for search
and search and replace.