figbert.com-website

[ACTIVE] the website and home of figbert on the clearnet
git clone git://git.figbert.com/figbert.com-website.git
Log | Files | Refs | README | LICENSE

commit 79724ccf0844a2baed7c2fa3cd39d5d1e32d7d8c
parent 89f7ffc4e7f9c7ffd838bd5e6bd35407b345c862
Author: FIGBERT <figbert@figbert.com>
Date:   Thu, 21 Jan 2021 15:20:07 -0800

Add "My First RegEx" post

Diffstat:
Acontent/posts/my-first-regex.md | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+), 0 deletions(-)

diff --git a/content/posts/my-first-regex.md b/content/posts/my-first-regex.md @@ -0,0 +1,55 @@ ++++ +title = "My First RegEx" +description = "Yesterday, I wrote my first regular expression. I’ve always regarded regex as an arcane art of true shell wizards – and for the most part, I still do. Now though, I’ve gotten a glimpse of their world." +date = 2021-01-21 ++++ + +`(?<=\.\/IssuerIcons\/).*(?=\.png)` +<!-- more --> + +## What it does + +Let's break it apart piece by piece. It's meant to return the filename +from a given path in a specific format. When given +`./IssuerIcons/Example.png`, the script should return `Example`. + +The first section is a positive lookbehind: `(?<=\.\/IssuerIcons\/)`. +This asserts that the selected portion must by preceeded by +`./IssuerIcons/`. + +The section section is a pattern match: `.*`. This matches all +characters, excluding newlines, of any length. + +The third and final section is a positive lookforward: `(?=\.png)`. +This asserts that the selected portion must be followed by `.png`. + +## Background + +Yesterday, I wrote my first regular expression. I've always regarded +regex as an arcane art of true shell wizards – and for the most part, +I still do. Now though, I've gotten a glimpse of their world. + +I wrote this expression for [Tofu][tofu], an open-source 2FA app for +iOS. I had been thinking of making more "issuer icons" for the app +when I noticed that the icons were all designed in one Sketch file. +This could become a problem if two people were to edit the file at +one time, so I suggested a [solution][issue]. + +The author got back to me with another idea: ditch Sketch altogether, +and replace it with a shell script that generates icons from a +directory of `png`s. I [wrote it][pr]. I've since refined it, with +help from [ThinkChaos][tc], to make it independent of any preceding +directories using `sed`: `sed -E 's:.+/(.+)\.png:\1:'`. + +It was a really fun experience – I've never written bash before! It +reminded me a lot of Drew DeVault's post [Become shell literate][sl]. +I work primarily from my terminal, and am slowly working my way up to +true mastery – I'm nowhere near close, but this was a step in the right +direction. + +[tofu]: https://www.tofuauth.com/ +[issue]: https://github.com/calleerlandsson/Tofu/issues/52 +[pr]: https://github.com/calleerlandsson/Tofu/pull/60 +[sl]: https://drewdevault.com/2020/12/12/Shell-literacy.html +[tc]: https://github.com/ThinkChaos +