Allow the tags to have a template for the links.
optimise the regular expression for replacing vars.