Avoid to compile regex several times

This directive is exactly what I was looking for, thanks!
Just a (very) small improvement to avoid compiling the regex each time.