<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xml:base="https://bjorn.now/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Background-Work on bjorn.now</title><link>https://bjorn.now/tags/background-work/</link><description>Recent content in Background-Work on bjorn.now</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 09 Oct 2025 10:13:00 +0200</lastBuildDate><atom:link href="https://bjorn.now/tags/background-work/feed.xml" rel="self" type="application/rss+xml"/><item><title>The regex | (or) operator splits the pattern left or right unless explicitly grouped</title><link>https://bjorn.now/til/2025-10-08-regex-or-operator-splits-pattern-left-or-right-unless-constrained/?utm_medium=feed</link><pubDate>Wed, 08 Oct 2025 23:34:03 +0200</pubDate><guid>https://bjorn.now/til/2025-10-08-regex-or-operator-splits-pattern-left-or-right-unless-constrained/</guid><description>The regex | (or) operator splits the pattern left or right unless explicitly grouped. Group it using (pattern) if you need to use the match later, or as a non-capturing group (?:pattern) if you do it for clarity.
I used to think there was some magic rule about how | decided where to split, but it’s simply: characters and subpatterns concatenate into a single pattern first, then | splits the entire thing left and right unless you explicitly group it. That’s because | has the lowest precedence so all other operations happen first.
So while I used to think that prefix_cat|dog would match prefix_cat and prefix_dog, it actually matches prefix_cat and then dog.
And that exact problem in a real-world example, to find if a page is linking to another, both relative or full URL:</description><content:encoded><![CDATA[<p>The regex <code>|</code> (or) operator splits the pattern left or right unless explicitly grouped.
Group it using <code>(pattern)</code> if you need to use the match later,
or as a non-capturing group <code>(?:pattern)</code> if you do it for clarity.</p>
<p>I used to think there was some magic rule about how <code>|</code> decided where to split,
but it&rsquo;s simply: characters and subpatterns concatenate into a single pattern first,
then <code>|</code> splits the entire thing left and right unless you explicitly group it.
That&rsquo;s because <code>|</code> <a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04_08">has the lowest precedence</a> so <em>all other</em> operations happen first.</p>
<p>So while I used to think that <code>prefix_cat|dog</code> would match <code>prefix_cat</code> and <code>prefix_dog</code>,
it actually matches <code>prefix_cat</code> and then <code>dog</code>.</p>
<p>And that exact problem in a real-world example, to find if a page is linking to another, both relative or full URL:</p>
<p>The regex <code>&lt;a[^&gt;]+href=[&quot;']https://www.example.com/page|/page</code> will match <code>/page</code>,
just as in the <code>dog</code> example, it&rsquo;s splitting the whole pattern and isn&rsquo;t what I want.</p>
<p>See it in action with <a href="https://regex101.com/r/6RylLz/2">the excellent Regex101.com</a>:</p>
<figure><img src="/img/2025/10-regex-01.png"
    alt="The Regex101.com site showing the Regex in action and that it matches /page">
</figure>

<p>To make it do what I want I need to constrain it in a capturing group <code>(pattern)</code>,
and since I don&rsquo;t want to reference the group later,
I constrain it inside a non-capturing group <code>(?:pattern)</code>.</p>
<p>That gives me the pattern <code>&lt;a[^&gt;]+href=[&quot;'](?:https://www\.example\.com/page|/page)</code>,
and <a href="https://regex101.com/r/kgeGyp/3">then it matches</a> both the full URL (<a href="https://www.example.com/page">https://www.example.com/page</a>) and the relative URL (/page):</p>
<figure><img src="/img/2025/10-regex-02.png"
    alt="The Regex101.com site showing the Regex in action and that it matches both links per the pattern as I intended">
</figure>

<p>I love Regex101.com. 🙂
I have commented gnarly regexes in my code with links to it,
so colleagues can paste them there and understand what&rsquo;s going on.
The sidebar explains what each subpattern does,
and the color highlighting shows what matches what in real-time.</p>]]></content:encoded></item><item><title>Recycling bins are for packaging, not the products</title><link>https://bjorn.now/til/2025-09-23-recycling-bins-are-for-packaging/?utm_medium=feed</link><pubDate>Tue, 23 Sep 2025 11:43:42 +0200</pubDate><guid>https://bjorn.now/til/2025-09-23-recycling-bins-are-for-packaging/</guid><description>Recycling bins are for packaging, not the products themselves. Wooden ice cream stick? That’s “other,” it’s part of the product, at least in Karlstad. The wrapper? That goes in the appropriate recycling bin based on material.
This seems to be based on EU law, which makes sense, so I’ll assume the gist of this is true in other EU countries too.</description><content:encoded><![CDATA[<p>Recycling bins are for packaging, not the products themselves. Wooden ice cream stick? That&rsquo;s &ldquo;other,&rdquo; it&rsquo;s part of the product, at least <a href="https://karlstadsenergi.se/atervinning/sortera-ditt-avfall-ratt">in Karlstad</a>. The wrapper? That goes in the appropriate recycling bin based on material.</p>
<p>This seems to be based on EU law, which makes sense, so I&rsquo;ll assume the gist of this is true in other EU countries too.</p>
<p>This has to do with &ldquo;<a href="https://karlstadsenergi.se/atervinning/sortera-ditt-avfall-ratt/sortera-en-forpackning-eller-foremal">producentansvar</a>&rdquo; (&ldquo;producer responsibility&rdquo;) which by law requires producers of products to be responsible for the recycling of the packaging, by joining a &ldquo;collection system that takes operative and financial responsibility for collecting and managing packaging material.&quot;<a href="https://www.riksdagen.se/sv/dokument-och-lagar/dokument/svensk-forfattningssamling/forordning-20181462-om-producentansvar-for_sfs-2018-1462/">1 § 3</a></p>
<p>This sounds like systems thinking in play: By making producers responsible for recycling, they&rsquo;re incentivized to create packaging that&rsquo;s both easy to identify/recycle (cheaper for them) and easy for consumers to sort correctly (to hit reuse targets).</p>
<p>I watched Chris Spargo&rsquo;s video on <a href="https://www.youtube.com/watch?v=fuwaOiTHl7U">Why recycling in England is so complicated?</a> yesterday, which explains how England is going through this shift to Extended Producer Responsibility (EPR) right now, and without seeing that video it wouldn&rsquo;t have clicked as easy when I was reading this now.</p>
<p>(The egg shells don&rsquo;t qualify as food waste while bones do, I don&rsquo;t know what to make of that, and apparently it&rsquo;s the opposite in my mom&rsquo;s municipality 🤷)</p>]]></content:encoded></item><item><title>YAML does *not* support unsplatting/merging lists</title><link>https://bjorn.now/til/2025-08-15-yaml-does-not-support-unsplatting-lists-and-thats-intentional-https/?utm_medium=feed</link><pubDate>Fri, 15 Aug 2025 21:19:18 +0800</pubDate><guid>https://bjorn.now/til/2025-08-15-yaml-does-not-support-unsplatting-lists-and-thats-intentional-https/</guid><description>YAML does not support unsplatting lists (basically, merging list items inline like you can with objects) and that’s intentional.</description><content:encoded><![CDATA[<p>YAML does not support unsplatting lists (basically, merging list items inline like you can with objects) and <a href="https://github.com/yaml/yaml/issues/35">that&rsquo;s intentional</a>.</p>
<p>So if you have a document like below, there is no syntax to make the <code>commands</code> a three item list:</p>
<div class=" copy-enabled">
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nn">---</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">example</span><span class="p">:</span><span class="w"> </span><span class="cp">&amp;example</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;Hello&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;World!&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="s2">&#34;hello&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">commands</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">&lt;&lt; *example</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;Oho!&#34;</span></span></span></code></pre></div>
</div>
<p><strong>WILL NOT</strong> turn into:</p>
<div class=" copy-enabled">
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nn">---</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">example</span><span class="p">:</span><span class="w"> </span><span class="cp">&amp;example</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;Hello&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;World!&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="s2">&#34;hello&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="nt">commands</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;Hello&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;World!&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="s2">&#34;Oho!&#34;</span></span></span></code></pre></div>
</div>
<p>…and just because before I found the issue where it was described that this isn&rsquo;t happening <a href="https://github.com/gaqzi/test-go-yaml">I had made a test repo</a> to try and understand if it was a library/usage issue, because I noticed I could get things running on CI with <code>&lt;&lt; *example</code> which syntax didn&rsquo;t give syntax error, but also did <em>nothing</em> when running on Drone CI.</p>]]></content:encoded></item></channel></rss>