<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/atom.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Posts tagged: regex</title>
  <id>https://waylonwalker.com/tags/regex/atom.xml</id>
  <updated>2024-10-08T13:36:25Z</updated>
  <subtitle>All posts with the tag &#34;regex&#34;</subtitle>
  <link href="https://waylonwalker.com/tags/regex/" rel="alternate" type="text/html"></link>
  <link href="https://waylonwalker.com/tags/regex/atom.xml" rel="self" type="application/atom+xml"></link>
  <author>
    <name>Waylon Walker</name>
  </author>
  <generator uri="https://github.com/WaylonWalker/markata-go">markata-go</generator>
  <entry>
    <title>💭 Support regex substitution command · Issue #2232 · helix-edito...</title>
    <id>https://waylonwalker.com/thought-407/</id>
    <updated>2024-10-08T13:36:25Z</updated>
    <published>2024-10-08T13:36:25Z</published>
    <link href="https://waylonwalker.com/thought-407/" rel="alternate" type="text/html"></link>
    <summary type="text">!https://github.com/helix-editor/helix/issues/2232#issuecomment-1228632218</summary>
    <content type="html">&lt;div class=&#34;embed-card embed-card-external&#34;&gt;&#xA;  &lt;a href=&#34;https://github.com/helix-editor/helix/issues/2232#issuecomment-1228632218&#34; class=&#34;embed-card-link&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&#xA;    &lt;div class=&#34;embed-card-image&#34;&gt;&#xA;      &lt;img class=&#34;glightbox&#34; src=&#34;https://opengraph.githubassets.com/6070a27597ac258b977bcb6e14aad6075dc9a5bba312a6b515fc74353a5b7731/helix-editor/helix/issues/2232&#34; alt=&#34;Support regex substitution command  · Issue #2232 · helix-editor/helix — Support regex substitution, comparable to vim :s or VSCode search &amp;amp; replace. I propose supporting regex replacements for selection s, files/, and the workspace scopes &amp;lt;space&amp;gt; + /. This could be acc...&#34; loading=&#34;lazy&#34;/ data-glightbox=&#34;description: Support regex substitution command  · Issue #2232 · helix-editor/helix — Support regex substitution, comparable to vim :s or VSCode search &amp;amp; replace. I propose supporting regex replacements for selection s, files/, and the workspace scopes &amp;lt;space&amp;gt; + /. This could be acc...&#34;&gt;&#xA;    &lt;/div&gt;&#xA;    &lt;div class=&#34;embed-card-content&#34;&gt;&#xA;      &lt;div class=&#34;embed-card-title&#34;&gt;Support regex substitution command  · Issue #2232 · helix-editor/helix&lt;/div&gt;&#xA;      &lt;div class=&#34;embed-card-description&#34;&gt;Support regex substitution, comparable to vim :s or VSCode search &amp;amp; replace. I propose supporting regex replacements for selection s, files/, and the workspace scopes &amp;lt;space&amp;gt; + /. This could be acc...&lt;/div&gt;&#xA;      &lt;div class=&#34;embed-card-meta&#34;&gt;GitHub · github.com&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;Here is a really good vim substitute with regex capture groups, saving this one for a rainy day.&lt;/p&gt;&#xA;&lt;pre class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;*&lt;/span&gt; Reading 1: This is a title to a link&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;*&lt;/span&gt; Reading 2: This is another title&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;:%s/\v(: )(.+)$/\1\[\2\]\(&lt;/code&gt;&lt;/p&gt;&#xA;&lt;pre class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;*&lt;/span&gt; Reading 1: [This is a title to a link](&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;*&lt;/span&gt; Reading 2: [This is another title](&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&#34;admonition note&#34;&gt;&#xA;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;&#xA;&lt;p&gt;This post is a &lt;a href=&#34;/thoughts/&#34; class=&#34;wikilink&#34; data-title=&#34;Thoughts&#34; data-description=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34; data-date=&#34;2024-04-01&#34; data-preview=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34;&gt;thought&lt;/a&gt;. It’s a short note that I make&#xA;about someone else’s content online &lt;a href=&#34;/tags/thoughts/&#34; class=&#34;hashtag-tag&#34; data-tag=&#34;thoughts&#34; data-count=&#34;2&#34; data-reading-time=&#34;3&#34; data-reading-time-text=&#34;3 minutes&#34;&gt;#thoughts&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/div&gt;&#xA;</content>
    <author>
      <name>Waylon Walker</name>
      <email>hello@waylonwalker.com</email>
      <uri>https://waylonwalker.com</uri>
    </author>
  </entry>
  <entry>
    <title>💭 Find And Replace one eyed kirby</title>
    <id>https://waylonwalker.com/thought-327/</id>
    <updated>2024-06-30T17:30:38Z</updated>
    <published>2024-06-30T17:30:38Z</published>
    <link href="https://waylonwalker.com/thought-327/" rel="alternate" type="text/html"></link>
    <summary type="text">!https://www.youtube.com/shorts/v2a6Nv7RSd0</summary>
    <content type="html">&lt;div class=&#34;embed-card embed-card-external embed-card-provider-youtube&#34;&gt;&#xA;  &lt;div class=&#34;embed-card-rich&#34;&gt;&#xA;&lt;lite-youtube videoid=&#34;v2a6Nv7RSd0&#34; title=&#34;Find And Replace&#34; playlabel=&#34;Play: Find And Replace&#34;&gt;&lt;/lite-youtube&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;another great use and demo of the one eyed fighting kirby&lt;/p&gt;&#xA;&lt;div class=&#34;admonition note&#34;&gt;&#xA;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;&#xA;&lt;p&gt;This post is a &lt;a href=&#34;/thoughts/&#34; class=&#34;wikilink&#34; data-title=&#34;Thoughts&#34; data-description=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34; data-date=&#34;2024-04-01&#34; data-preview=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34;&gt;thought&lt;/a&gt;. It’s a short note that I make&#xA;about someone else’s content online &lt;a href=&#34;/tags/thoughts/&#34; class=&#34;hashtag-tag&#34; data-tag=&#34;thoughts&#34; data-count=&#34;2&#34; data-reading-time=&#34;3&#34; data-reading-time-text=&#34;3 minutes&#34;&gt;#thoughts&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/div&gt;&#xA;</content>
    <author>
      <name>Waylon Walker</name>
      <email>hello@waylonwalker.com</email>
      <uri>https://waylonwalker.com</uri>
    </author>
  </entry>
  <entry>
    <title>💭 The One Eyed Fighting Kirby</title>
    <id>https://waylonwalker.com/thought-200/</id>
    <updated>2024-01-26T17:21:06Z</updated>
    <published>2024-01-26T17:21:06Z</published>
    <link href="https://waylonwalker.com/thought-200/" rel="alternate" type="text/html"></link>
    <summary type="text">!https://www.youtube.com/watch?v=9_Ekt1PZBzQ&amp;t=351s</summary>
    <content type="html">&lt;div class=&#34;embed-card embed-card-external embed-card-provider-youtube&#34;&gt;&#xA;  &lt;div class=&#34;embed-card-rich&#34;&gt;&#xA;&lt;lite-youtube videoid=&#34;9_Ekt1PZBzQ&#34; title=&#34;Why I Fire Programmers | Prime Reacts&#34; playlabel=&#34;Play: Why I Fire Programmers | Prime Reacts&#34;&gt;&lt;/lite-youtube&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;I’ve heard prime say just give it the one eyed fighting kirby so many times, and execute it few times, and there is no way to find it online, so this will be the link that I will come to, when I need to remember what @theprimeagen means when he says Give it the one eyed fighting kirby.&lt;/p&gt;&#xA;&lt;pre class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;sr&#34;&gt;/\(.*\);/&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;console&lt;/span&gt;.&lt;span class=&#34;nx&#34;&gt;log&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;\&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;so-what-is-this&#34;&gt;So what is this? &lt;a href=&#34;#so-what-is-this&#34; class=&#34;heading-anchor&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;This is a vim substitute comand to replace text in the buffer.  the one eyed fighting kirby is a regex capture group to capture everything between matches, and assign it a value to place back in after the match.&lt;/p&gt;&#xA;&lt;p&gt;substitute in a nutshell, &lt;code&gt;:s/&amp;lt;what you want to replace&amp;gt;/&amp;lt;what you want to replace with&amp;gt;&lt;/code&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;more-examples&#34;&gt;More examples &lt;a href=&#34;#more-examples&#34; class=&#34;heading-anchor&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;Here is a contrived example of text.&lt;/p&gt;&#xA;&lt;pre class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;here there&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;from here go there&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;here = some_fuction(there)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now for some reason I want to switch all of the words here and there.  I can do that with three capture groups, \1 is here, \2 is everything between, \3 is there.&lt;/p&gt;&#xA;&lt;pre class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;%&lt;span class=&#34;nx&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;sr&#34;&gt;/\(here\)\(.*\)\(there\)/&lt;/span&gt;\&lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;\&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;\&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;blockquote&gt;&#xA;&lt;p&gt;Just give it the one eyed fighting kirby&lt;/p&gt;&#xA;&lt;p&gt;~Prime&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h2 id=&#34;still-struggling&#34;&gt;still struggling &lt;a href=&#34;#still-struggling&#34; class=&#34;heading-anchor&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;I thought this explaination from phind was good and more verbose than mine.&lt;/p&gt;&#xA;&lt;hr/&gt;&#xA;&lt;p&gt;describe this vim substitute regex&lt;/p&gt;&#xA;&lt;p&gt;:%s/(here)(.&lt;em&gt;)(there)/\3\2\1&#xA;ANSWER | PHIND V9 MODEL&#xA;The given Vim substitute regex :%s/(here)(.&lt;/em&gt;)(there)/\3\2\1 performs the following operation:&lt;/p&gt;&#xA;&lt;p&gt;%s initiates the substitute command. The percent sign % indicates that the operation should be performed across the entire file, not just the current line 2.&#xA;(here) is a capturing group that matches the word “here”. The parentheses ( and ) are used to define a group, and the content inside them is what the group will match 3.&#xA;(.&lt;em&gt;) is another capturing group that matches any sequence of characters. The .&lt;/em&gt; inside the group is a wildcard that matches any character (except a newline), and the * quantifier means “zero or more of the preceding element”. So, this group will match any sequence of characters 2.&#xA;(there) is yet another capturing group that matches the word “there”. This group will match the word “there” that appears after the word “here” and any sequence of characters 3.&#xA;/\3\2\1 is the replacement part of the command. Here, \3, \2, and \1 are backreferences to the matched groups. They correspond to the words “there”, any sequence of characters, and “here”, in that order. So, this command replaces the matched pattern with the word “there”, followed by any sequence of characters, and ending with the word “here” 4.&#xA;So, in summary, this command searches for the pattern “here”, followed by any sequence of characters, and ending with “there”, and replaces it with the same pattern but reversed (“there”, followed by the original sequence of characters, and ending with “here”).&lt;/p&gt;&#xA;&lt;p&gt;I used this techniq on &lt;a href=&#34;/refactoring-into-wikilinks/&#34; class=&#34;wikilink&#34; data-title=&#34;Refactoring one line links into wikilinks&#34; data-description=&#34;Previously I had setup a feature of my website to expand one line links into a card. This was not a standard, even to the point that some formatters wrap the...&#34; data-date=&#34;2024-05-31&#34; data-preview=&#34;Previously I had setup a feature of my website to expand one line links into a card. This was not a standard, even to the point that some formatters wrap the...&#34;&gt;Refactoring one line links into wikilinks&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;admonition note&#34;&gt;&#xA;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;&#xA;&lt;p&gt;This post is a &lt;a href=&#34;/thoughts/&#34; class=&#34;wikilink&#34; data-title=&#34;Thoughts&#34; data-description=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34; data-date=&#34;2024-04-01&#34; data-preview=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34;&gt;thought&lt;/a&gt;. It’s a short note that I make&#xA;about someone else’s content online &lt;a href=&#34;/tags/thoughts/&#34; class=&#34;hashtag-tag&#34; data-tag=&#34;thoughts&#34; data-count=&#34;2&#34; data-reading-time=&#34;3&#34; data-reading-time-text=&#34;3 minutes&#34;&gt;#thoughts&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/div&gt;&#xA;</content>
    <author>
      <name>Waylon Walker</name>
      <email>hello@waylonwalker.com</email>
      <uri>https://waylonwalker.com</uri>
    </author>
  </entry>
  <entry>
    <title>💭 Bob Belderbos on X: &#34;Forget Python for a sec, here&#39;s how Vim h...</title>
    <id>https://waylonwalker.com/thought-124/</id>
    <updated>2023-10-05T01:34:19Z</updated>
    <published>2023-10-05T01:34:19Z</published>
    <link href="https://waylonwalker.com/thought-124/" rel="alternate" type="text/html"></link>
    <summary type="text">!https://twitter.com/bbelderbos/status/1709525676154368055</summary>
    <content type="html">&lt;div class=&#34;embed-card embed-card-external&#34;&gt;&#xA;  &lt;a href=&#34;https://twitter.com/bbelderbos/status/1709525676154368055&#34; class=&#34;embed-card-link&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&#xA;    &lt;div class=&#34;embed-card-content&#34;&gt;&#xA;      &lt;div class=&#34;embed-card-title&#34;&gt;External Link&lt;/div&gt;&#xA;      &lt;div class=&#34;embed-card-meta&#34;&gt;X (formerly Twitter) · twitter.com&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;I need to learn regex capture groups better.  This is so dang powerful. I really like the \v that bob uses here, it really does cut down on the terseness of all the special characters.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I wanted to replace all occurrences of:&lt;/p&gt;&#xA;&lt;p&gt;name,name@example.com,0,171,,2023-09-21&lt;/p&gt;&#xA;&lt;p&gt;With:&lt;/p&gt;&#xA;&lt;p&gt;name,name@example.com&lt;/p&gt;&#xA;&lt;p&gt;Easy to do with Python, but what about a bit of &amp;gt; regex in Vim?&lt;/p&gt;&#xA;&lt;p&gt;:%s/\v([^,]+,[^,]+),.*/\1/&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;div class=&#34;admonition note&#34;&gt;&#xA;&lt;p class=&#34;admonition-title&#34;&gt;Note&lt;/p&gt;&#xA;&lt;p&gt;This post is a &lt;a href=&#34;/thoughts/&#34; class=&#34;wikilink&#34; data-title=&#34;Thoughts&#34; data-description=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34; data-date=&#34;2024-04-01&#34; data-preview=&#34;These are generally my thoughts on a web page or some sort of url, except a rare few don&amp;#39;t have a link. These are dual published off of my...&#34;&gt;thought&lt;/a&gt;. It’s a short note that I make&#xA;about someone else’s content online &lt;a href=&#34;/tags/thoughts/&#34; class=&#34;hashtag-tag&#34; data-tag=&#34;thoughts&#34; data-count=&#34;2&#34; data-reading-time=&#34;3&#34; data-reading-time-text=&#34;3 minutes&#34;&gt;#thoughts&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/div&gt;&#xA;</content>
    <author>
      <name>Waylon Walker</name>
      <email>hello@waylonwalker.com</email>
      <uri>https://waylonwalker.com</uri>
    </author>
  </entry>
</feed>