Escape special characters in a string for building a regular expression.