Cheatsheet Pages / Regex Cheatsheet

How to anchor a regex to the start or end — ^ and $

The match only counts at the very beginning or the very end of the string — or of each line, with the multiline flag.

Patterns use the syntax shared by PCRE / Python / JavaScript; engine differences are flagged in the cheatsheet where they matter. Test any pattern at regex101.com — and pick the matching engine.

^Hello
# matches only if the string/line starts with "Hello"
\d+$
# matches only if the string/line ends with digits
Regex Cheatsheet one-page card — patterns that actually work
The full one-page card — Regex Cheatsheet. Get the complete cheatsheet on GitHub