snipt

Ctrl+h for KB shortcuts
#51142

Text only

REGEXP - usefull

1
2
3
4
5
in var_dump array
regexp
=(>|>)\n\s*(array|string|int)\([0-9]+\)
replace by 
=>
https://snipt.net/embed/3407a80a555c9d931de0479c8700e0f6/
https://snipt.net/raw/3407a80a555c9d931de0479c8700e0f6/
3407a80a555c9d931de0479c8700e0f6
text
Text only
5
2014-04-03T12:51:37
True
False
Dec 04, 2012 at 12:59 AM
/api/public/snipt/51142/
regexp-usefull
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>in var_dump array </span><span id="L-2"><a name="L-2"></a>regexp </span><span id="L-3"><a name="L-3"></a>=(&gt;|&amp;gt;)\n\s*(array|string|int)\([0-9]+\) </span><span id="L-4"><a name="L-4"></a>replace by </span><span id="L-5"><a name="L-5"></a>=&gt; </span></pre></div> </td></tr></table>
regexp, usefull
#45657

CoffeeScript

RegExp_escape

# http://xkr.us/js/regexregex
RegExp_escape = (str) -> str.replace(/[\\\^\$*+[\]?{}.=!:(|)]/g, "\\$&")
https://snipt.net/embed/3e394a878c40720181f8c83cea7fbd01/
https://snipt.net/raw/3e394a878c40720181f8c83cea7fbd01/
3e394a878c40720181f8c83cea7fbd01
coffee-script
CoffeeScript
3
2014-04-13T05:49:47
True
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 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
#39935

PHP

Create hyperlinks within text

1
2
3
4
function create_hyperlinks_within_text( $text )
{
    return preg_replace('@(http)?(s)?(://)?(([-\w]+\.)+([^\s]+)+[^,.\s])@', '<a href="http$2://$4">$1$2$3$4</a>', $text );
}
https://snipt.net/embed/fb1ba49b2d5b01df81043606cf52617a/
https://snipt.net/raw/fb1ba49b2d5b01df81043606cf52617a/
fb1ba49b2d5b01df81043606cf52617a
php
PHP
4
2014-04-13T16:08:09
True
False
/api/public/snipt/39935/
create-hyperlinks-within-text
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">function create_hyperlinks_within_text( $text )</span> </span><span id="L-2"><a name="L-2"></a><span class="x">{</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> return preg_replace(&#39;@(http)?(s)?(://)?(([-\w]+\.)+([^\s]+)+[^,.\s])@&#39;, &#39;&lt;a href=&quot;http$2://$4&quot;&gt;$1$2$3$4&lt;/a&gt;&#39;, $text );</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
anchor, regexp, tag, text
#38878

VimL

Strip DOS-style line endings in vim

:%s/\r\(\n\)/\1/g
https://snipt.net/embed/1beb82c8e7bdfb978d31888983ac9e55/
https://snipt.net/raw/1beb82c8e7bdfb978d31888983ac9e55/
1beb82c8e7bdfb978d31888983ac9e55
vim
VimL
1
2014-04-16T18:57:47
True
False
/api/public/snipt/38878/
strip-dos-style-line-endings-in-vim
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="p">:</span>%<span class="k">s</span><span class="sr">/\r\(\n\)/</span>\<span class="m">1</span>/<span class="k">g</span> </span></pre></div> </td></tr></table>
regexp, vim
#37558

Ruby

dollar, euro, sterling, yen

money = /[$\u20AC\u{a3}\u{a5}]/
https://snipt.net/embed/c42c6cd6f827178eb94bb873a3eae346/
https://snipt.net/raw/c42c6cd6f827178eb94bb873a3eae346/
c42c6cd6f827178eb94bb873a3eae346
rb
Ruby
1
2014-04-15T11:15:17
True
False
/api/public/snipt/37558/
dollar-euro-sterling-yen
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="n">money</span> <span class="o">=</span> <span class="sr">/[$\u20AC\u{a3}\u{a5}]/</span> </span></pre></div> </td></tr></table>
regexp, ruby