Regex template factory

The regex for the Template creation now uses match groups instead of dynamic sub-stringing.
I find this slightly better to read, and this is a precursor to the templates_ignore_case branch.