Fixed regex issues with template system