Regex Cheatsheet
Searchable regex syntax reference with plain meanings, examples, and copyable common patterns.
Matches tokens, meanings, and examples. The whole reference is on this page; nothing is sent anywhere.
^Start of the string, or start of a line with the m flag.
^Hi matches "Hi there" but not "Say Hi"
$End of the string, or end of a line with the m flag.
end$ matches "the end"
\bWord boundary: the edge between a word character and a non-word character.
\bcat\b matches "cat" but not "concat"
\BAny position that is not a word boundary.
\Bcat matches "cat" inside "concat"
\ANot in JavaScriptStart of the string only, never a line start, even in multiline mode.
In PCRE, \Ahello anchors to the very start
\zNot in JavaScriptAbsolute end of the string, ignoring any trailing newline rules.
In PCRE, end\z requires "end" to close the string
\ZNot in JavaScriptEnd of the string, or just before a final newline.
In PCRE, end\Z also matches before a trailing "\n"
.Any single character except a line break. With the s flag it matches those too.
c.t matches "cat", "cot", and "c9t"
\dA digit, 0 through 9.
\d{4} matches "2026"
\DAny character that is not a digit.
\D+ matches "abc-" in "abc-123"
\wA word character: a letter, a digit, or an underscore.
\w+ matches "hello_42"
\WAny character that is not a word character.
\W matches the space in "a b"
\sA whitespace character: space, tab, or line break.
a\sb matches "a b"
\SAny character that is not whitespace.
\S+ matches "word" up to the next space
[abc]Any one of the characters listed inside the brackets.
[bcr]at matches "bat", "cat", and "rat"
[^abc]Any one character that is not listed inside the brackets.
[^0-9] matches any single non-digit
[a-z]Any one character in the given range. Ranges can be combined.
[a-f0-9] matches one lowercase hex digit
\p{L}Needs the u flagAny character with the given Unicode property, here any letter.
\p{L}+ with the u flag matches "héllo"
\hNot in JavaScriptHorizontal whitespace only: spaces and tabs, not line breaks.
In PCRE, a\hb matches "a b" but not across lines
\RNot in JavaScriptAny line break sequence: \n, \r, or \r\n.
In PCRE, line1\Rline2 matches across any newline style
*Zero or more of the preceding item, as many as possible.
ab*c matches "ac", "abc", and "abbc"
+One or more of the preceding item, as many as possible.
ab+c matches "abc" but not "ac"
?Zero or one of the preceding item.
colou?r matches "color" and "colour"
{3}Exactly that many of the preceding item.
\d{3} matches "123"
{2,4}Between the two counts of the preceding item, inclusive.
a{2,4} matches "aa", "aaa", or "aaaa"
{2,}At least that many of the preceding item.
x{2,} matches "xx" and any longer run
*?Lazy zero or more: matches as few characters as possible.
".*?" matches the first quoted part instead of spanning two quotes
+?Lazy one or more: matches as few characters as possible.
<.+?> matches "<a>" instead of the whole "<a><b>"
??Lazy zero or one: prefers to match nothing.
ab??b matches "ab" using the empty option first
*+Not in JavaScriptPossessive zero or more: matches greedily and never gives characters back.
In PCRE, a*+a can never match, since a*+ keeps every "a"
++Not in JavaScriptPossessive one or more: greedy with no backtracking.
In PCRE, \d++ locks in the full digit run
(abc)Capturing group: matches and remembers the text for later use.
(\d+)px captures "24" from "24px"
(?:abc)Non-capturing group: groups without remembering the text.
(?:ab)+ matches "abab" without creating a capture
(?<name>abc)Named capturing group: remembers the text under a name.
(?<year>\d{4}) captures "2026" as year
\1Backreference: matches the same text as capturing group 1.
(\w)\1 matches the doubled "l" in "hello"
\k<name>Backreference by name: matches the same text as the named group.
(?<q>["'])\w+\k<q> matches "word" or 'word'
a|bAlternation: matches the option on either side.
cat|dog matches "cat" or "dog"
(?>abc)Not in JavaScriptAtomic group: once matched, the engine never backtracks into it.
In PCRE, (?>a+)a can never match
(?=abc)Lookahead: the position must be followed by this, without consuming it.
\d+(?=px) matches "24" in "24px"
(?!abc)Negative lookahead: the position must not be followed by this.
\d+(?!px) matches "24" in "24em"
(?<=abc)Lookbehind: the position must be preceded by this, without consuming it.
(?<=\$)\d+ matches "30" in "$30"
(?<!abc)Negative lookbehind: the position must not be preceded by this.
(?<!-)\d+ skips digits right after a hyphen
\KNot in JavaScriptResets the match start: everything before it is dropped from the match.
In PCRE, foo\Kbar matches only "bar" in "foobar"
gGlobal: find every match, not just the first one.
/a/g finds all three matches in "banana"
iCase-insensitive: letters match regardless of case.
/hello/i matches "Hello" and "HELLO"
mMultiline: ^ and $ match at the start and end of each line.
/^item/m matches "item" at the start of any line
sDotall: the dot also matches line breaks.
/a.b/s matches "a\nb"
uUnicode: the pattern is read as code points and \p{...} works.
/\p{Emoji}/u can match a single emoji
yJavaScript onlySticky: the match must start exactly at the current position.
Useful for tokenizers that walk a string step by step
vJavaScript onlyUnicode sets: extended class syntax with set operations.
/[\p{L}--[a-z]]/v matches letters except lowercase ASCII
xNot in JavaScriptFree spacing: whitespace and comments inside the pattern are ignored.
In PCRE, patterns can be split over lines with comments
\Escapes a metacharacter so it matches literally.
\. matches a literal dot, not any character
\nLine feed (newline) character.
a\nb matches "a" and "b" on separate lines
\tTab character.
\t\d matches a tab followed by a digit
\rCarriage return character.
\r\n matches a Windows-style line ending
\0The NUL character (character code zero).
\0 matches a NUL byte in a string
\xhhThe character with the given 2-digit hex code.
\x41 matches "A"
\uhhhhThe character with the given 4-digit hex code.
\u20AC matches the euro sign
\u{hhhh}Needs the u flagThe character with the given code point, any length.
\u{1F600} with the u flag matches a grinning face emoji
\cXA control character, where X is a letter.
\cI matches a tab (Ctrl-I)
[\w.+-]+@[\w-]+\.[\w.-]+Practical email matcher for everyday validation.
Matches "user.name+tag@example.co.uk"
https?:\/\/\S+HTTP or HTTPS URL, up to the next whitespace.
Matches "https://example.com/path?q=1"
\d{4}-\d{2}-\d{2}Date in YYYY-MM-DD form.
Matches "2026-07-05"
([01]\d|2[0-3]):[0-5]\dTime of day in 24-hour HH:MM form.
Matches "09:30" and "23:59" but not "24:00"
((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)IPv4 address with each octet limited to 0-255.
Matches "192.168.0.1" but not "999.1.1.1"
#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b3-digit or 6-digit hex color code.
Matches "#fff" and "#6366f1"
^[a-z0-9]+(?:-[a-z0-9]+)*$Lowercase URL slug with single hyphens between words.
Matches "regex-cheatsheet" but not "-bad-" or "a--b"
^\s+|\s+$Leading and trailing whitespace, for replacing with an empty string.
Turns " hi " into "hi" when replaced
How to use this regex cheatsheet
Search for a token
Type a token, a word from its meaning, or part of an example to filter the list as you type.
Narrow by category
Pick a category pill such as quantifiers or lookarounds to show only that section of the reference.
Copy what you need
Click the copy button on any row to copy that token, or copy the whole filtered cheatsheet at once.
Why use this tool
Every core token covered
Anchors, character classes, quantifiers, groups, backreferences, lookarounds, flags, and escapes, each with a short plain meaning and a worked example.
Ready-made common patterns
Copyable patterns for emails, URLs, ISO dates, 24-hour times, IPv4 addresses, hex color codes, and URL slugs.
Flavor notes for JavaScript
Tokens that do not work in JavaScript, such as possessive quantifiers and atomic groups, carry a clear badge so you know before you paste.
Instant search
Filter by the token itself, by its meaning, or by example text, and the list narrows with every keystroke.
Copy on click
Each row has a copy button, and the whole visible cheatsheet can be copied as plain text in one click.
Free and runs in your browser
No signup and nothing is sent anywhere; the full reference loads with the page.
About this tool
This regex cheatsheet is a searchable reference for regular expression syntax. It lists the core tokens across eight sections: anchors, character classes, quantifiers, groups and references, lookarounds, flags, escapes, and a set of ready-made common patterns. Each entry pairs the token with a plain-English meaning and a small example showing what it matches, so you can confirm behaviour before dropping it into real code.
The filter box matches against the token, the meaning, and the example text, so typing "boundary" finds \b just as quickly as typing the token itself. Category pills narrow the list to one section, and every section can be collapsed for faster scanning. Regex flavors differ in small but painful ways, so tokens that are not supported in JavaScript, such as atomic groups, possessive quantifiers, and \K, carry a clear badge, as do tokens that need a specific flag, like Unicode property escapes.
Use it while writing validation rules, log filters, search-and-replace commands, or editor searches. The common patterns section covers everyday jobs like matching emails, ISO dates, IPv4 addresses, and hex color codes, each copyable in one click. If you like this style of lookup, the HTTP status codes list and the ASCII table follow the same search-and-copy pattern, and the MIME type lookup helps when a pattern needs to match file types.
Frequently asked questions
- How does the cheatsheet work?
- Type in the filter box to narrow the list by token, meaning, or example text, or pick a category pill to show one section. Every entry has its own copy button, and the button at the bottom copies everything currently visible.
- Which regex flavor does it cover?
- The core table applies to nearly every flavor. Tokens missing in JavaScript, like possessive quantifiers, atomic groups, and \K, are badged "Not in JavaScript", and JavaScript-only flags like sticky (y) and Unicode sets (v) are marked too.
- Is my search sent anywhere?
- No. The whole reference is part of the page and filtering happens in your browser; nothing is sent to a server.
- Can I copy more than one token at a time?
- Yes. The button at the bottom copies every visible entry, grouped by section, as plain text. Filter first to copy just the rows you need.
- Are the common patterns production-ready?
- They are practical everyday patterns, not full standards implementations. The email pattern, for example, accepts realistic addresses without implementing the entire specification, which is usually what validation needs.
- What do the badges on some rows mean?
- They flag flavor differences. "Not in JavaScript" marks tokens that only work in engines like PCRE, "JavaScript only" marks flags other flavors lack, and "Needs the u flag" marks Unicode escapes that require it.
Related tools
HTTP Status Codes Reference
Search every HTTP status code, see what it means, and copy it with a click.
ASCII Table Reference
The full ASCII character set with decimal, hex, octal, binary, and HTML codes. Search by code, character, or name.
MIME Type Lookup
Type a file extension to get its MIME type, or paste a MIME type to see which extensions use it.
API Key Generator
Generate cryptographically random API keys and tokens in hex, base62, or base64url, with control over length, an optional prefix, and bulk output.
Atbash Cipher
Mirror the alphabet so A swaps with Z, B with Y, and so on. Atbash is its own inverse, so one field both encodes and decodes as you type.
Base32 Encoder and Decoder
Encode text to standard Base32 and decode Base32 back to text, following RFC 4648.