Change to a recursive regex to allow sub-templates