escape regular expressions; fix typo in variable name

Escape characters which are part of the regular expression syntax. This should fix #1098 in master.