Only compile regex for hacking_except_format once

Instead of using re.match which compiles the regex each time use
re.compile and re.search. A small scale timeit test shows this method
reduces the time needed by about 60%.

Change-Id: I613a4c07776ec9e00bb09bd9c52074862436b559