snipt

Ctrl+h for KB shortcuts

CoffeeScript

RegExp_escape

# http://xkr.us/js/regexregex
RegExp_escape = (str) -> str.replace(/[\\\^\$*+[\]?{}.=!:(|)]/g, "\\$&")
https://snipt.net/embed/3e394a878c40720181f8c83cea7fbd01/
/raw/3e394a878c40720181f8c83cea7fbd01/
3e394a878c40720181f8c83cea7fbd01
coffee-script
CoffeeScript
3
2019-08-17T20:32:53
True
False
False
Aug 14, 2012 at 03:54 AM
/api/public/snipt/45657/
regexp_escape
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># http://xkr.us/js/regexregex</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">RegExp_escape = </span><span class="nf">(str) -&gt;</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/[\\\^\$*+[\]?{}.=!:(|)]/g</span><span class="p">,</span> <span class="s">&quot;\\$&amp;&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
regexp