On 21 Mar 2014, at 16:38, C. Scott Ananian <[email protected]> wrote:
> ```js
> function replaceTitle(title, str) {
> return str.replace(new RegExp(title), "...");
> }
> ```
>
> There ought to be a standard simple way of writing this correctly.
I’ve used something like this in the past:
RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
};
It escapes some characters that do not strictly need escaping to avoid bugs in
ancient JavaScript engines. A standardized version could be even simpler, and
would indeed be very welcome IMHO.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss