Regex Cheat Sheet
A complete reference for regular expression syntax — character classes, quantifiers, anchors, groups, lookaheads, flags, and 12 copy-paste patterns for common validation tasks.
Try these patterns live in the Regex Tester →Character Classes
Character classes match a single character from a defined set. Square brackets create custom sets; backslash shortcuts provide common presets.
.\d\D\w\W\s\S[abc][^abc][a-z]Quantifiers
Quantifiers control how many times the preceding token must appear. Add ? after any quantifier to make it lazy (match as few characters as possible).
*+?{n}{n,}{n,m}Anchors
Anchors match positions in the string rather than actual characters. They are zero-width assertions.
^$\b\BGroups & References
Groups let you apply quantifiers to multiple tokens, capture submatches for later use, and write lookahead/lookbehind assertions.
(...)(?:...)(?=...)(?!...)(?<=...)(?<!...)\1Flags
Flags modify how the entire pattern is interpreted. In JavaScript, flags are appended after the closing slash: /pattern/gi
gimsuyCommon Patterns
Ready-to-use regex patterns for the most common validation and extraction tasks. Test them in the Regex Tester before using in production.
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}https?:\/\/[^\s/$.?#].[^\s]*(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\b\+?1?[\s.\-]?\(?\d{3}\)?[\s.\-]?\d{3}[\s.\-]?\d{4}\d{5}(?:-\d{4})?^[a-zA-Z0-9_]{3,20}$^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%]).{8,}$<([a-z][a-z0-9]*)(?:[^>]*)?>.*?<\/\1>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?Test your regex patterns
Paste any pattern from this cheat sheet and see real-time match highlighting with group extraction.
Regex FAQ
Answers to the most common questions about regular expression syntax and usage.
What is a regular expression (regex)?+
A regular expression is a sequence of characters that defines a search pattern. They are used for string matching, validation, extraction, and replacement in programming languages like JavaScript, Python, Java, and many others.
What is the difference between .* and .+?+
.* matches zero or more of any character, while .+ matches one or more. Use .+ when the content must be present, and .* when the match may be empty.
What does the ^ anchor do in regex?+
The ^ anchor matches the beginning of a string (or line in multiline mode). For example, ^hello matches 'hello world' but not 'say hello'. Inside a character class like [^abc], it negates the class instead.
What is a non-capturing group (?:...)?+
(?:...) groups part of a pattern without creating a capture group. This is useful when you need to apply a quantifier to multiple tokens but do not need to reference the matched text later. It is also slightly more performant than a capturing group.
What are regex lookaheads and lookbehinds?+
Lookaheads (?=...) and (?!...) assert whether a pattern does or does not follow the current position without consuming characters. Lookbehinds (?<=...) and (?
What regex flags are available in JavaScript?+
JavaScript supports: g (global – find all matches), i (case-insensitive), m (multiline – ^ and $ match line boundaries), s (dotAll – . matches newlines), u (unicode – full Unicode support), and y (sticky – matches from lastIndex only).