Fixed template issue with escaping single quotes, new lines etc. Regular expressions moved to variables in order to compile it only once.