No Login Data Private Local Save

Interactive Regex Cheatsheet - Online Quick Reference

14
0
0
0
Copied!

Interactive Regex Cheatsheet

Test, learn & copy regular expressions — live matching, searchable reference, and practical examples

Live Regex Tester
/ /
RESULTS: 0 matches Error
Type a regex pattern and test text to see matches highlighted here...
MATCH DETAILS
Character Classes
\d
\D
\w
\W
\s
\S
.
[abc]
[^abc]
[a-z]
Quantifiers
*
+
?
{n}
{n,}
{n,m}
*?
+?
Anchors & Boundaries
^
$
\b
\B
\A
\z
Groups & Lookaround
(…)
(?:…)
(?=…)
(?!…)
(?<=…)
(?
|
\1
Escape Sequences
\n
\t
\r
\\
\.
\*
\+
\x{…}
Common Shorthands
[0-9]+
[A-Za-z]+
[A-Za-z0-9]+
#[0-9A-Fa-f]{6}
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
Common Regex Examples — Click to Try
Email
user@domain.com
Try It
URL
https://...
Try It
Phone
+1-555-123-4567
Try It
Date (YYYY-MM-DD)
2024-01-15
Try It
Hex Color
#ff5733
Try It
SSN (US)
123-45-6789
Try It
Frequently Asked Questions
A regular expression (regex) is a sequence of characters that defines a search pattern. It is used for string matching, validation, extraction, and replacement in text processing. Regex engines interpret special metacharacters (like ., *, +, [], ()) to create flexible and powerful search patterns. Regex is supported in virtually all programming languages including JavaScript, Python, Java, PHP, and .NET.
Greedy quantifiers (*, +, ?, {n,m}) match as many characters as possible while still allowing the overall pattern to succeed. Lazy quantifiers (*?, +?, ??, {n,m}?) match as few characters as possible. For example, given the string "<div>hello</div>", the greedy pattern <.*> matches the entire string, while the lazy pattern <.*?> matches just "<div>".
To match special regex metacharacters literally, you must escape them with a backslash \. Common metacharacters that need escaping include: ., *, +, ?, ^, $, {, }, (, ), [, ], |, /, and \. For example, to match a literal period, use \.. Inside a character class [], most metacharacters lose their special meaning and don't need escaping.
Lookahead (?=…) and lookbehind (?<=…) are zero-width assertions that check if a pattern exists (or doesn't exist) ahead of or behind the current position, without consuming characters. Positive lookahead (?=pattern) asserts the pattern does follow. Negative lookahead (?!pattern) asserts it does not follow. Similarly, positive lookbehind (?<=pattern) checks behind, and negative lookbehind (? checks that a pattern does not precede. These are invaluable for complex validation without including the assertion in the match.
The global flag ('g') makes the regex engine find all matches in the input string rather than stopping after the first match. Without 'g', only the first match is returned. With 'g', methods like match() return an array of all matches, and matchAll() returns an iterator over all match details including capture groups. In JavaScript, the 'g' flag also affects the behavior of exec() by maintaining a lastIndex for iterative matching.
Capturing groups (pattern) store the matched content in memory, accessible via backreferences (\1, \2) or in results arrays. Non-capturing groups (?:pattern) group patterns for logical or repetition purposes without storing the match. Non-capturing groups are more memory-efficient and should be preferred when you don't need to reference the matched content later. They also keep result arrays cleaner by not adding unnecessary capture entries.
You can test regex interactively right on this page using the Live Regex Tester at the top. Simply enter your pattern, select flags, and type or paste test text — matches are highlighted in real-time with full match details. You can also copy any pattern from the cheatsheet below directly into the tester. For more advanced debugging, tools like Regex101, RegExr, and RegexBuddy offer step-by-step explanations and visualization.
The most common flags are: g (global — find all matches), i (case-insensitive — ignore letter casing), m (multiline — ^ and $ match line starts/ends), s (dotall — . matches newline characters), u (unicode — enables full Unicode support), and y (sticky — matches only from lastIndex position). Flags vary slightly across programming languages and regex engines.
Pro Tip: Click any regex code in the cheatsheet to copy it. Use the search box to filter entries. Click example cards to auto-fill the tester. All matching happens locally in your browser — no data is sent anywhere.