Improve regexEscape and add tests.