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-09-28T11:27:35
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 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-09-28T13:02:52
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 id="L-1"><a name="L-1"></a><span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;email&quot;</span> <span class="na">pattern=</span><span class="s">&quot;[^ @]*@[^ @]*&quot;</span> <span class="na">value=</span><span class="s">&quot;&quot;</span><span class="nt">&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-08-17T00:38:25
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-09-27T03:46:55
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 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-09-21T10:55:57
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 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-09-22T03:17:11
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 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

JavaScript

extract the css transformation properties with Javascript

1
2
3
4
5
6
// src:http://stackoverflow.com/questions/3451402/how-to-extract-the-webkit-transformation-syntax-in-javascript
// credit : http://whattheheadsaid.com/
//
//
$(this).css('-webkit-transform').match(/[^()\s]+(?=,|\))/g);
// -> ["0.6", "0px", "2236px", "12deg"]
https://snipt.net/embed/6bd1edb1f8c82c7d09df91f49eeb50b9/
https://snipt.net/raw/6bd1edb1f8c82c7d09df91f49eeb50b9/
6bd1edb1f8c82c7d09df91f49eeb50b9
js
JavaScript
6
2016-09-28T08:26:57
True
False
False
Sep 27, 2012 at 12:51 PM
/api/public/snipt/47725/
extract-the-css-transformation-properties-with-javascript
<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> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1">// src:http://stackoverflow.com/questions/3451402/how-to-extract-the-webkit-transformation-syntax-in-javascript</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// credit : http://whattheheadsaid.com/</span> </span><span id="L-3"><a name="L-3"></a><span class="c1">//</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">//</span> </span><span id="L-5"><a name="L-5"></a><span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">css</span><span class="p">(</span><span class="s1">&#39;-webkit-transform&#39;</span><span class="p">).</span><span class="nx">match</span><span class="p">(</span><span class="sr">/[^()\s]+(?=,|\))/g</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="c1">// -&gt; [&quot;0.6&quot;, &quot;0px&quot;, &quot;2236px&quot;, &quot;12deg&quot;]</span> </span></pre></div> </td></tr></table>
"css transform", css3, javascript, js, regex, rotate, rotateX, rotateY, scaleX, scaleY, transform, translate, translateX, translateY
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.