I am trying to cleanup some Javascript code using jshint. In a third-party script that is being used, jshint complains about unescaped javascript in this line:
var cleanString = deaccentedString.replace(/([|()[{.+*?^$\\])/g,"\\$1");
I’d also like to understand what this regular expression does, but I don’t see it. Can anyone tell me what this is for and how to write it in a cleaned up way?
Thank your for any hints.
It matches any of the following characters:
|()[{.+*?^$\and replaces it with its escaped counterpart (backslash plus that character).While it is legal in many regex dialects to include an unescaped
[inside a character class, it can trigger an error in others, so try this:(the unnecessary capturing group could be dropped, too.)