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/
/raw/940f084dd40897180b5a15ed7a27be6c/
940f084dd40897180b5a15ed7a27be6c
bash
Bash
4
2019-06-15T13:42:49
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/
/raw/c8184b363995c6ad6fcc91dea159f18d/
c8184b363995c6ad6fcc91dea159f18d
html
HTML
1
2019-06-13T19:10:24
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/
/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

Text only

Extract Anchor Text from URL

1
2
3
4
5
http://www.domain.com/directory/service.html#service_2
In the URL above, this regex will only pull 'service_2'.
============================================================

\b(?<=#)[a-z][a-z0-9_]*\b
https://snipt.net/embed/132ddc493cd60f24650c281d567cd19b/
/raw/132ddc493cd60f24650c281d567cd19b/
132ddc493cd60f24650c281d567cd19b
text
Text only
5
2019-06-13T19:10:58
True
False
False
/api/public/snipt/53776/
extract-anchor-text-from-url
<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></span><span id="L-1"><a name="L-1"></a>http://www.domain.com/directory/service.html#service_2 </span><span id="L-2"><a name="L-2"></a>In the URL above, this regex will only pull &#39;service_2&#39;. </span><span id="L-3"><a name="L-3"></a>============================================================ </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>\b(?&lt;=#)[a-z][a-z0-9_]*\b </span></pre></div> </td></tr></table>
regex

VimL

Regex find until next Quote

:job_title => "(.*?)", 
#this would match all instances of :job_title => "blah blah"
https://snipt.net/embed/159e33f89abcf85636b46db7477f32a6/
/raw/159e33f89abcf85636b46db7477f32a6/
159e33f89abcf85636b46db7477f32a6
vim
VimL
2
2019-06-15T23:23:56
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/
/raw/a0e51032f1bea1078f9d2c58c56d5087/
a0e51032f1bea1078f9d2c58c56d5087
text
Text only
1
2019-06-13T19:13:18
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