Skip to content

Instantly share code, notes, and snippets.

View shelleymcq's full-sized avatar

Shelley McHardy shelleymcq

View GitHub Profile
@shelleymcq
shelleymcq / Regex-Tutorial.md
Last active August 24, 2021 19:35
A Regular Expression Tutorial

Regex Tutorial

"Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems." -Jamie Zawinski

Summary

A regex, or regular expression, defines a sequence or pattern of characters that can be used to search a text.

There are typically two ways to approach dissecting and understanding a new function. You can backwards engineer a complete function and try to break down each part, or you can build it up from scratch, analyzing each step as you go. I took the latter approach in order to see the function in its most simplest steps to inform this tutorial.

I have created a regular expression that checks if a string is a valid postal code for the Netherlands. I chose the Dutch code because it included an interesting pattern - four numbers followed by two uppercase letters, excluding a few combinations of negative historical significance.