Cheat sheets / Regex

Regex Cheat Sheet

The 36 pieces of regular expression syntax you actually use, plus a row of ready-made patterns. Click one to copy it.

This page also works as a hotkey overlay. Hold Ctrl+Space to see it, let go to hide it. What is this?

Characters

How many

These apply to whatever comes right before them. By default they grab as much as they can; add ? to grab as little as possible.

Position and choice

Groups

Lookarounds and flags

Lookarounds check what is next to the match without including it in the result.

Ready-made patterns

This syntax is shared by JavaScript, Python, Java, C# and PCRE (PHP, grep -P). Named groups are written (?P<name>...) in Python. To try a pattern out, regex101.com shows what it matches as you type.

Keep this cheat sheet on a hotkey

BrainRAM is a small free app for Windows. Hold Ctrl+Space and this page appears on top of whatever you are doing. Let go and it's gone. Click a cell and it's copied.

Each row is one topic, named at its left edge, in the same order as this page. So ready-made patterns is always the bottom row, and after a few days you stop reading and just reach for the spot.

  1. Download BrainRAM Free, no account, works offline. The installer isn't code-signed yet, so Windows shows a blue warning: click More info, then Run anyway.
  2. Add this page to BrainRAM Opens BrainRAM with this page ready to import.

BrainRAM runs on Windows today. The macOS and Linux versions are on the way.

Email me when mine is ready
This page as BrainRAM shows it while you hold the hotkey.

More cheat sheets