/ Published in: JavaScript
![](/img/icon_sav.png?v3)
Usefull Regular Expressions enhancement. Simplifies standard string operations escaping special chars. And also saves precompiled REs for a speed increase.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
RegExp.escape = function(text) { if (!arguments.callee.sRE) { var specials = [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\\\' ]; arguments.callee.sRE = new RegExp( '(\\\\' + specials.join('|\\\\') + ')', 'g' ); } return text.replace(arguments.callee.sRE, '\\\\$1'); }
Comments
![RSS Feed for Comments RSS Icon](/images/rss.png?v3)