fix regexp to work for more complex templates