Searchable reference guide for regular expressions tokens, quantifiers, lookarounds, and common recipes.
Loading tool
About Regex Cheat Sheet
A searchable reference for regular expressions in JavaScript syntax: character classes, anchors and boundaries, quantifiers, groups and backreferences, lookarounds, flags (including s, u, v, y and d), escapes and replacement patterns like $1 and $<name>. It also includes common recipes for emails, URLs, ISO dates, hex colors, IPv4 addresses, slugs and password rules. Each token has a description, many have examples, and any token can be copied.
Common uses
- Look up lookahead or lookbehind syntax
- Find the right flag for multiline or Unicode matching
- Copy a starting pattern for validating a date, email or IP address
- Check which replacement token inserts a named group
FAQ
- What is the difference between greedy and lazy quantifiers?
- Greedy quantifiers like * and + match as much as possible, while lazy versions like *? and +? match as little as possible. For example, <.+> matches '<a><b>' whole, but <.+?> matches '<a>' first.
- What does a lookahead do in regex?
- A lookahead (?=...) checks that some text follows the current position without including it in the match. A negative lookahead (?!...) checks that it does not follow.
- What does the m flag do?
- With the m (multiline) flag, ^ and $ match at the start and end of each line instead of only at the start and end of the whole string.
- Does JavaScript support lookbehind?
- Yes. Lookbehind (?<=...) and (?<!...) are part of ES2018 and are supported in all current major browsers and Node.js.