Derivatives for Regular Expressions

Published: 2021-12-21

We show how to implement Regular Expressions using Brzozowski's Derivatives. This tutorial shows you how to implement a regular expression matching function using only two very simple functions. It is programming language agnostic, so you can do the exercise in any language you are comfortable with: javascript, python, Elixir, Go, Haskell, etc. It also contains several examples for each function so you first develop an intuition for the function before implementing it. The implementation is based on Brzozowski's derivatives, which is simpler that the usual automata based implementation of regular expression matchers and a great intro to some functional programming concepts as well. Derivatives of Regular Expressions - Brzozowski , explained using Pacman. In this video it is explained how to write a regular expression matching function using only two functions. Pacman is used as an analogy to help to explain the derivative and nullable functions. This video is now also available in blog format.