How I finally learnt regex, using spaced repetition

I’m not exaggerating when I say that in the two years since I started to write code, I’ve tried to learn how to use regex about 5 times.

Here’s the general pattern:

  1. Run through a regex tutorial (article or video)
  2. Feel happy that now I know regex, at least enough to apply it to the task at hand
  3. Do other stuff that doesn’t involve regex for a few weeks / months
  4. Hit a task that calls for some regex expertise
  5. Realise I don’t really remember how regex works
  6. Sigh and start again

Sure, maybe this cycle gets a little quicker each time, but it still feels wildly inefficient.

Why tutorials don’t work in this learning scenario#

We have to remember that tutorials are an inherently passive way of learning. We also tend to consume them once, and then move onto something else.

Don’t get me wrong - they can be super useful for certain types of learning. I especially like to lean on them if I need a quick contextual overview of a brand new technology before diving into the detail, or if I need to get up to speed quickly on a new technology which I know I’m going to use very regularly (for example, a new application monitoring tool).

But in the cases where I’m unable to put a new skill learnt from a tutorial into immediate and sustained practice, it just isn’t going to stick in the long term.

Hence my regex learning block. A tutorial might help me implement some nice regex right then and there. But I use regex infrequently and my new knowledge evaporates soon after I’ve moved onto the next thing.

Spaced repetition to the rescue#

Luckily, there is a much better way to learn the stuff which you might not be able to practice regularly - in a way that makes it stick.

I recently found out about a learning technique called spaced repetition, commonly achieved using flashcards. As the Wikipedia summary notes, “spaced repetition is commonly applied in contexts in which a learner must acquire many items and retain them indefinitely in memory.”

In practice, the learner takes in some new information and their understanding is then tested with questions on flashcards. Questions which were previously answered unsuccessfully get repeated more often.

Crucially, there is a delay before the next round of flashcards. The forced break leverages the spacing effect, which proves that learning is more effective when study sessions are spaced out. This is because spreading out our learning by a reasonable interval allows us to forget and then recall information - thereby cementing it into our long-term memory.

Spaced repetition tools for programmers#

Sounds pretty useful for learning - and more importantly remembering - programming skills right? Whether we’re talking about git commands, syntax for a language you’re not using everyday, niche vim motions or my personal regex bugbear - it’s easy to see how spaced repetition can help.

There’s a lot of good flashcard software out there. Why not use a tool like Anki to create your own spaced repetition learning system?

I personally use Roam for all my note-taking, and absolutely love how easy it is to set up flashcards right in my notes, to be displayed to me at a later date (oh hey #roamcult).

I’m also using a brilliant website called Execute Programme to learn regex using spaced repetition and I can confirm that I could now match a UK-based phone number in my sleep.

For the first time ever, I’m pretty confident I’ll be able to say the same thing in 6 month’s time.