Precompile regex into a Pattern object

Avoid recompiling the regex on each upload by putting regex into a
Pattern object