While going through Elixir with a group of beginners, we got to a point I wanted to explain to them what a regex is. I thought of an analogy that they could relate with.

What if you think about Regex as a riddle with many solutions? For example:

  • It has 4 legs
  • It has 2 eyes
  • It has a neck
  • It has a tail

What is it?

The answer can be any of the following:

  1. Hyena
  2. Giraffe
  3. Goat

The answer is definitely not the following:

  1. Fish
  2. Snake
  3. Chicken

A regex is a set of rules that has a lot of answers