Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Bash

sed append to match

1
2
3
4
file="/path/to/file"
regex="find this .*"
suffix="-suffix"
sed -i "s/$regex/&$suffix/" $file
https://snipt.net/embed/940f084dd40897180b5a15ed7a27be6c/
https://snipt.net/raw/940f084dd40897180b5a15ed7a27be6c/
940f084dd40897180b5a15ed7a27be6c
bash
Bash
4
2016-12-08T04:18:13
True
False
False
Oct 13, 2015 at 06:33 AM
/api/public/snipt/141656/
sed-append-to-match
<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></span><span id="L-1"><a name="L-1"></a><span class="nv">file</span><span class="o">=</span><span class="s2">&quot;/path/to/file&quot;</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">regex</span><span class="o">=</span><span class="s2">&quot;find this .*&quot;</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">suffix</span><span class="o">=</span><span class="s2">&quot;-suffix&quot;</span> </span><span id="L-4"><a name="L-4"></a>sed -i <span class="s2">&quot;s/</span><span class="nv">$regex</span><span class="s2">/&amp;</span><span class="nv">$suffix</span><span class="s2">/&quot;</span> <span class="nv">$file</span> </span></pre></div> </td></tr></table>
append, bash, linux, regex, sed

HTML

HTML5 Regular Expressions email validation

<input type="email" pattern="[^ @]*@[^ @]*" value="">
https://snipt.net/embed/c8184b363995c6ad6fcc91dea159f18d/
https://snipt.net/raw/c8184b363995c6ad6fcc91dea159f18d/
c8184b363995c6ad6fcc91dea159f18d
html
HTML
1
2016-12-04T10:39:46
True
False
False
May 28, 2013 at 12:57 PM
/api/public/snipt/62418/
html5-regular-expressions-email-validation
<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></span><span id="L-1"><a name="L-1"></a><span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;email&quot;</span> <span class="na">pattern</span><span class="o">=</span><span class="s">&quot;[^ @]*@[^ @]*&quot;</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;&quot;</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
"regular expressions", email, html5, regex, validation

C#

Remove <p></p> tags from a string...

literal.Text = Regex.Replace(q.Custom2, "<.*?>", string.Empty);  // Added as a temp fix to remove <p>...</p> tags from Custom2 field in database.  CKEditor is adding those tags when not wanted..
https://snipt.net/embed/7fab991d8a7efd347845fb6b64800560/
https://snipt.net/raw/7fab991d8a7efd347845fb6b64800560/
7fab991d8a7efd347845fb6b64800560
csharp
C#
1
2016-10-14T17:52:53
True
False
True
May 02, 2013 at 03:20 PM
/api/public/snipt/60512/
remove-pp-tags-from-a-string
<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">literal</span><span class="p">.</span><span class="n">Text</span> <span class="p">=</span> <span class="n">Regex</span><span class="p">.</span><span class="n">Replace</span><span class="p">(</span><span class="n">q</span><span class="p">.</span><span class="n">Custom2</span><span class="p">,</span> <span class="s">&quot;&lt;.*?&gt;&quot;</span><span class="p">,</span> <span class="kt">string</span><span class="p">.</span><span class="n">Empty</span><span class="p">);</span> <span class="c1">// Added as a temp fix to remove &lt;p&gt;...&lt;/p&gt; tags from Custom2 field in database. CKEditor is adding those tags when not wanted..</span> </span></pre></div> </td></tr></table>
regex, tags

VimL

Regex find until next Quote

:job_title => "(.*?)", 
#this would match all instances of :job_title => "blah blah"
https://snipt.net/embed/159e33f89abcf85636b46db7477f32a6/
https://snipt.net/raw/159e33f89abcf85636b46db7477f32a6/
159e33f89abcf85636b46db7477f32a6
vim
VimL
2
2016-12-08T00:22:04
True
False
False
Nov 26, 2012 at 06:45 PM
/api/public/snipt/50790/
regex-find-until-next-quote
<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="p">:</span>job_title <span class="p">=&gt;</span> <span class="s2">&quot;(.*?)&quot;</span><span class="p">,</span> </span><span id="L-2"><a name="L-2"></a>#this would <span class="k">match</span> <span class="k">all</span> instances of :job_title <span class="p">=&gt;</span> <span class="s2">&quot;blah blah&quot;</span> </span></pre></div> </td></tr></table>
regex, vim

Text only

regex remove css comments

\/\*[^\*]+\*\/
https://snipt.net/embed/a0e51032f1bea1078f9d2c58c56d5087/
https://snipt.net/raw/a0e51032f1bea1078f9d2c58c56d5087/
a0e51032f1bea1078f9d2c58c56d5087
text
Text only
1
2016-12-04T10:12:02
True
False
False
Oct 18, 2012 at 10:26 AM
/api/public/snipt/48751/
regex-remove-css-comments
<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></span><span id="L-1"><a name="L-1"></a>\/\*[^\*]+\*\/ </span></pre></div> </td></tr></table>
regex

MySQL

Select users where email is invalid

1
2
3
SELECT * 
FROM users
WHERE email NOT REGEXP  '^[A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}$'
https://snipt.net/embed/712560d14b48df6885ae6618f92e8397/
https://snipt.net/raw/712560d14b48df6885ae6618f92e8397/
712560d14b48df6885ae6618f92e8397
mysql
MySQL
3
2016-12-08T03:52:42
True
False
False
Oct 09, 2012 at 11:11 AM
/api/public/snipt/48307/
select-users-where-email-is-invalid
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">SELECT</span> <span class="o">*</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">users</span> </span><span id="L-3"><a name="L-3"></a><span class="k">WHERE</span> <span class="n">email</span> <span class="k">NOT</span> <span class="k">REGEXP</span> <span class="s1">&#39;^[A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}$&#39;</span> </span></pre></div> </td></tr></table>
email, mysql, regex, validate
Copyrighted, illegal, or inappropriate content? Email [email protected].