/ Published in: JavaScript
URL: http://stackoverflow.com/questions/280793/case-insensitive-string-replacement-in-javascript
Escape all special regex characters (.*+?|()[]{}) from a string. Useful when dynamically building a Regular Expression object based on input text that could hold regex characters.
Expand |
Embed | Plain Text
RegExp.escape = function(str) { var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\ return str.replace(specials, "\\$&"); }
You need to login to post a comment.
