define regex outside of middleware to add performance

http://jsperf.com/creating-a-regex-in-and-outside-a-loop/5 shows the performance gain.