Cache regular expressions

Compiling them on every loop iteration is expensive.
Style
Merge pull request #7 from indragiek/cache-regex

Cache regular expressions