Regex Tester & Debugger
Write a pattern, see every match highlighted, and learn what each token does.
- Free
- No sign-up
- Runs in your browser
Updated
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
Match Results
Regex guide — learn by example
Regular expressions (regex) are patterns used to match text. Press Try it on any example to load it into the tester above.
Literal Characters — Match Exact Text
The simplest regex matches exact text. Just type the word or phrase you want to find.
Find a specific word
/hello/giMatches the word "hello" regardless of case (i flag). The g flag finds all occurrences, not just the first.
Match a phrase with spaces
/ice cream/gSpaces are literal in regex — this matches the exact phrase "ice cream" with the space.
Character Classes — Match Types of Characters
Use shorthand codes to match categories: \d for digits, \w for word characters, \s for spaces, and . for any character.
\d — Match any digit
/\d+/g\d matches any digit [0-9]. The + means "one or more". So \d+ matches sequences of digits like 1234, 2024, 03, 15, 99, 50, 3.
\w — Match word characters
/\w+/g\w matches letters, digits, and underscore [a-zA-Z0-9_]. Notice @#$% are NOT matched because they aren't word characters.
. (dot) — Match any character
/c.t/gThe dot matches ANY single character. So c.t matches cat, cot, cut, c@t, c3t — but not "c t" (space counts!) and not "cart" (too many chars between c and t).
\s — Match whitespace
/\s+/g\s matches spaces, tabs (\t), newlines (\n), and other whitespace. \s+ matches one or more whitespace characters in a row.
Character Sets [...] — Custom Groups
Square brackets let you define custom sets of characters to match. Use [abc] for specific chars, [a-z] for ranges, and [^abc] to negate.
[aeiou] — Match vowels only
/[aeiou]/giMatches any single character that is a, e, i, o, or u. Each vowel is matched individually.
[0-9a-fA-F] — Hex digits
/#[0-9a-fA-F]{3,6}/gThe range [0-9a-fA-F] matches any hex digit. {3,6} means the hex part must be 3 to 6 characters long.
[^...] — Negated set (NOT these characters)
/[^a-zA-Z\s]/gThe ^ inside brackets means NOT. This matches anything that is NOT a letter and NOT whitespace — so it finds digits, punctuation, symbols.
Quantifiers — How Many Times
Control how many times a pattern repeats: * (0+), + (1+), ? (0 or 1), {n} (exact), {n,m} (range).
* — Zero or more
/go*d/go* means zero or more o's. So it matches: gd (0 o's), god (1 o), good (2 o's), goood (3 o's), etc.
+ — One or more
/go+d/go+ means one or more o's. Unlike *, it requires at least one o. So "gd" does NOT match, but god, good, goood all do.
? — Optional (zero or one)
/colou?r/giu? means the u is optional (0 or 1 times). Matches both "color" (American) and "colour" (British) but not "colouur".
{n,m} — Specific range
/\d{2,4}/g{2,4} means between 2 and 4 times. \d{2,4} matches 2 to 4 digit sequences. "1" alone doesn't match (too short). "12345" partially matches as "1234".
Anchors — Position Matching
Anchors don't match characters — they match positions. ^ matches start, $ matches end, \b matches word boundaries.
^ and $ — Start and end of line
/^Error.*$/gm^ means start of line (with m flag). $ means end of line. Combined, this matches entire lines that START with "Error". The m flag makes ^ and $ work per-line instead of whole-string.
\b — Word boundary
/\bcat\b/gi\b marks a word boundary (between a word char and a non-word char). \bcat\b matches "cat" as a whole word — NOT "cat" inside "concatenate" or "category".
Groups & Capture — Extract Parts
Parentheses () create groups that capture matched text. Use them to extract specific parts from a match.
Basic capture groups
/(\d{4})-(\d{2})-(\d{2})/gEach set of parentheses captures a group. Group 1 = year (\d{4}), Group 2 = month (\d{2}), Group 3 = day (\d{2}). Click a match to see groups.
Named capture groups
/(?<protocol>https?)://(?<domain>[\w.-]+)/g(?<name>...) creates a named group. Instead of Group 1/2, you get meaningful names like "protocol" and "domain" — much easier to read.
Non-capturing groups (?:...)
/(?:Mr|Mrs|Ms)\.?\s(\w+)/g(?:...) groups without capturing. The title alternatives (Mr|Mrs|Ms) are grouped but not captured. Only the name (\w+) is captured as Group 1.
Alternation — OR Logic
The pipe | means OR — match this pattern OR that pattern.
Simple alternation
/cat|dog|bird/giMatches "cat" OR "dog" OR "bird" anywhere in the text. Simple and powerful for matching alternatives.
Alternation with groups
/(Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day/gGroups + alternation to match all valid day names. The prefix is captured as Group 1. "Funday" doesn't match because "Fun" isn't in the alternatives.
Lookahead & Lookbehind — Context Matching
Match a position where specific text appears before or after, without including that text in the match.
Positive lookahead (?=...)
/\w+(?=@)/g(?=@) means "followed by @" but @ is NOT included in the match. So it captures just the username part before the @.
Negative lookahead (?!...)
/\d+(?!\$|%)/g(?!\$|%) means "NOT followed by $ or %". Matches numbers that are NOT dollar amounts or percentages. 300, 400, and 500 match.
Positive lookbehind (?<=...)
/(?<=\$)\d+\.?\d*/g(?<=\$) means "preceded by $" but $ is NOT in the match. Captures only the numeric amount after the dollar sign.
Greedy vs Lazy — Controlling Match Length
By default, quantifiers are greedy (match as much as possible). Add ? to make them lazy (match as little as possible).
Greedy .* — matches too much
/<.+>/gGreedy .+ matches as MUCH as possible. It matches from the first < all the way to the LAST >, swallowing everything in between as one big match.
Lazy .+? — matches the minimum
/<.+?>/gAdding ? makes it lazy — .+? matches as LITTLE as possible. Now each HTML tag (<b>, </b>, <i>, </i>) is matched individually.
Practical Examples — Real-World Patterns
Combine everything you've learned into useful real-world patterns.
Extract image filenames
/[\w-]+\.(jpg|png|gif|svg|webp)/giMatches filenames ending with common image extensions. [\w-]+ matches the name part, \. matches the literal dot, and (jpg|png|...) matches image extensions.
Validate time format (HH:MM)
/^([01]\d|2[0-3]):[0-5]\d$/gmValidates 24-hour time. Hours: 00-23 ([01]\d covers 00-19, 2[0-3] covers 20-23). Minutes: 00-59 ([0-5]\d). Invalid entries like 24:00, 12:60, and 7:30 don't match.
Find duplicate words
/\b(\w+)\s+\1\b/gi\b(\w+) captures a word, \s+ matches spaces, \1 is a back-reference that matches the SAME text as Group 1. Finds repeated words like "is is" and "the the".
CSS hex color in code
/#(?:[0-9a-fA-F]{3}){1,2}\b/gMatches 3 or 6 digit hex colors. (?:[0-9a-fA-F]{3}) matches 3 hex chars, {1,2} means this group appears 1 or 2 times (for #333 or #FF5733).
What is it?
A regex tester lets you run a regular expression against sample text and see exactly what it matches. This one uses your browser's JavaScript RegExp engine, highlights matches as you type, lists numbered and named capture groups, explains the pattern token by token, and previews replacements with $1 or $<name>. Nothing is sent to a server.
How to use
- Type a pattern into the Pattern field, or pick one from Patterns.
- Toggle the flags you need: g, i, m, s or u.
- Paste text into Test String and read the highlighted matches and capture groups.
- Switch to Replace and enter a replacement string to preview the output.
- Copy the regex as /pattern/flags when it works.
Frequently asked questions
Is my text sent to a server?
No. Patterns and test strings are evaluated with the RegExp engine built into your browser, and the tool makes no network requests with your data.
Which regex flavor does this use?
JavaScript (ECMAScript), the same engine your browser and Node.js run. Patterns from PCRE or Python mostly work, but features like possessive quantifiers, atomic groups and inline modifiers such as (?i) are not supported.
Does this support lookbehind?
Yes. Positive (?<=...) and negative (?<!...) lookbehind work in every current browser, including Safari 16.4 and later. Lookahead (?=...) and (?!...) work too.
Why does my regex only find the first match?
The g (global) flag is off. Without it, JavaScript stops at the first match; turn g on to find all of them.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers like .* match as much text as possible, then back off; lazy ones like .*? match as little as possible. On <b>a</b><b>c</b>, <b>.*</b> matches the whole line while <b>.*?</b> matches each tag pair separately.
Which flags are available?
The toggles cover g (global), i (case-insensitive), m (multiline), s (dotAll) and u (unicode). The y (sticky), d (indices) and v (unicodeSets) flags are not offered.
Can a bad pattern freeze my browser?
With g on, the tool stops collecting matches after 200 ms or 5,000 results and shows a warning. A single catastrophic match cannot be interrupted mid-run, so avoid nested quantifiers like (a+)+ on long input.
How do I use capture groups in a replacement?
Switch to Replace and reference groups with $1, $2 and so on, or $<name> for named groups; $& inserts the whole match.