<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about regex)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/regex.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2025 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Wed, 09 Apr 2025 13:15:40 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Updating my cgit links for Luanti projects</title><link>https://bgstack15.ddns.net/blog/posts/2025/04/09/updating-my-cgit-links-for-luanti-projects/</link><dc:creator>bgstack15</dc:creator><description>&lt;p&gt;I decided that my thousands of &lt;a href="https://bgstack15.ddns.net/blog/outbound/https:/www.luanti.org/"&gt;Luanti&lt;/a&gt;-related repositories should be stored in their own &lt;a href="https://bgstack15.ddns.net/blog/outbound/https:/bigbangtheory.fandom.com/wiki/Sheldon%27s_Spot"&gt;special spot&lt;/a&gt;, er, heading in my &lt;a href="https://bgstack15.ddns.net/blog/cgit/luanti"&gt;cgit&lt;/a&gt;, visible in the whole list only on the &lt;a href="https://bgstack15.ddns.net/blog/cgit/?ofs=100"&gt;last page&lt;/a&gt;. I guess I can't link directly to just the heading in the whole list cgit, but at least you can view only those repos if desired with the first link.&lt;/p&gt;
&lt;p&gt;To adjust my recent blog posts that pointed to the old locations, I had to use some regex.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;vi $( grep -l -rI -P '(?&amp;lt;=\(\/cgit\/)[^\)]+' posts/2025 )
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This found any link that starts with &lt;code&gt;/cgit/&lt;/code&gt; so I can go edit it.&lt;/p&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;h3&gt;Weblinks&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://bgstack15.ddns.net/blog/outbound/https:/www.regular-expressions.info/lookaround.html"&gt;Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description><category>cgit</category><category>luanti</category><category>regex</category><guid>https://bgstack15.ddns.net/blog/posts/2025/04/09/updating-my-cgit-links-for-luanti-projects/</guid><pubDate>Wed, 09 Apr 2025 13:11:00 GMT</pubDate></item><item><title>vim set regextype perl</title><link>https://bgstack15.ddns.net/blog/posts/2017/04/07/vim-set-regextype-perl/</link><dc:creator>bgstack15</dc:creator><description>&lt;h2&gt;The problem&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.vim.org/"&gt;Vim&lt;/a&gt; is a great editor. I use it every day, and that
includes weekends. I've run into an issue where to search with the regular
expression &lt;strong&gt;(dest|path):&lt;/strong&gt; I needed to escape the parentheses and the pipe.
That gets tedious.&lt;/p&gt;
&lt;h2&gt;The solution&lt;/h2&gt;
&lt;p&gt;I found my solution at stackoverflow:
&lt;a href="http://stackoverflow.com/a/26600989/3569534"&gt;http://stackoverflow.com/questions/5770058/vim-and-regular-expression-what-
kind-of-regex-does-vim-
use/26600989#26600989&lt;/a&gt;. At the
beginning of your search expression, use &lt;strong&gt;\v&lt;/strong&gt; which then uses a "very magic"
regex mode in which fewer escapes are needed. &lt;code&gt;/\v(dest|path):&lt;/code&gt;&lt;/p&gt;</description><category>regex</category><category>vim</category><guid>https://bgstack15.ddns.net/blog/posts/2017/04/07/vim-set-regextype-perl/</guid><pubDate>Fri, 07 Apr 2017 13:48:18 GMT</pubDate></item><item><title>Hide comments and blank lines in file</title><link>https://bgstack15.ddns.net/blog/posts/2016/06/24/show-all-non-blank-non-comment-lines-in-file/</link><dc:creator>bgstack15</dc:creator><description>&lt;h2&gt;Hide comments and blank lines when viewing file&lt;/h2&gt;
&lt;h6&gt;Original title: Show all non-blank non-comment lines in file&lt;/h6&gt;
&lt;p&gt;If you want to see just the lines with content, such as in a config file, use
this one-liner:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;grep -viE '^\s*((#|;).*)?$' smb.conf
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;How it works&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;grep -v&lt;/strong&gt; means invert the selection, i.e., everything that does not match
this search. &lt;strong&gt;-iE&lt;/strong&gt; case Insensitive, and treat this as a regular Expression.
Technically there are no letters being searched, so the i is irrelevant, but I
always use it in my searches anyway. &lt;strong&gt;^&lt;/strong&gt; start of line &lt;strong&gt;\s&lt;/strong&gt;&lt;em&gt; white space,
any amount from zero onward. This is a greedy search, so it will match all the
white space (spaces, tabs, etc.) &lt;/em&gt;&lt;em&gt;(#|;)&lt;/em&gt;&lt;em&gt; either a pound or a semicolon,
which usually denote comments in config files (in my case, smb.conf)
&lt;/em&gt;&lt;em&gt;((#|;).&lt;/em&gt;)&lt;strong&gt; the above sentence, followed by any character (the period), and
any amount of those "any characters." &lt;/strong&gt;((#|;).&lt;em&gt;)?&lt;/em&gt;&lt;em&gt; the whole thing in
parentheses shown here, optionally. &lt;/em&gt;&lt;em&gt;$&lt;/em&gt;* end of line So any line that starts
with any amount of white space, followed by (a comment symbol, followed by
anything else) optionally, and the end of the line. So show everything but the
above sentence, and tada, just the important stuff.&lt;/p&gt;</description><category>bash</category><category>blank</category><category>comments</category><category>config</category><category>grep</category><category>hide</category><category>line</category><category>oneliner</category><category>regex</category><guid>https://bgstack15.ddns.net/blog/posts/2016/06/24/show-all-non-blank-non-comment-lines-in-file/</guid><pubDate>Fri, 24 Jun 2016 18:37:35 GMT</pubDate></item></channel></rss>