Test regular expressions with animated match highlighting.
Last updated
Flags
//g
Test stringPaste text to begin
Paste or type the text to test against…
MatchesNo matches
Matches appear here — indices, captured groups, and counts, all live.
What is a regex tester?
A regex tester lets you type a regular expression and immediately see what it matches in sample text. Developers use regex (regular expressions) to validate input, extract data from strings, search logs, clean text, build editor commands, and write search-and-replace rules.
Regex feels cryptic at first because a few symbols carry a lot of meaning. A live tester demystifies it: every character you type updates the highlighted matches and capture groups, so you can experiment until the pattern does exactly what you want.
Different programming languages use slightly different regex engines (JavaScript, PCRE, Python, Java, Go, .NET). The fundamentals — characters, character classes, quantifiers, anchors, and groups — work everywhere. The advanced features (lookbehind, named groups, possessive quantifiers) are where engines diverge.
What you'll learn while testing regex
A pattern describes the *shape* of text, not its meaning. \d+ matches a run of digits, but it doesn't know whether the number makes sense.
Flags change behavior: g finds every match, i ignores case, m makes ^ and $ match line ends, s lets . match newlines.
Capture groups (...) extract parts of a match, not just check whether the whole string matches — essential for parsing.
How to use the regex tester step by step
1
Type your pattern
Enter a regular expression in the pattern field. Don't include the surrounding / slashes — they're a JavaScript literal syntax, not part of the pattern itself.
2
Toggle the flags you need
Most often you'll want g (find all matches) and i (case-insensitive). Use m for line-by-line anchors and s to let . match newlines.
3
Paste your test string
Drop sample text into the test area. Matches highlight as you type, and capture groups are listed underneath the match list.
4
Read the match panel
Each match shows its position, full text, and any captured groups. Use this to verify the pattern catches what you want and skips what you don't.
5
Refine until it's correct
Tighten quantifiers, add anchors (^, $), or escape literal characters (\., \?) until the matches and groups are exactly what your code needs.
Regex cheat sheet
The 80% of regex you'll use 99% of the time. Bookmark this — it's the fastest way to remember the syntax. For the full grammar, see MDN's regular expressions guide.
Token
Meaning
Example
.
Any single character (except newline)
a.c matches abc, a-c
\d\D
Digit / non-digit
\d+ matches 123
\w\W
Word char (letter/digit/_) / non-word
\w+ matches hello_1
\s\S
Whitespace / non-whitespace
\s+ matches spaces and tabs
[abc]
Any of a, b, or c
[aeiou] matches a vowel
[^abc]
None of a, b, or c
[^0-9] matches non-digits
*+?
0+, 1+, 0 or 1 of the previous
a+ matches a, aaa
{n}{n,m}
Exactly n / between n and m
\d{3,5} 3 to 5 digits
^$
Start / end of string (or line with m)
^Error line begins with Error
(...)
Capture group
(\d+) captures the digits
(?:...)
Non-capturing group
(?:foo|bar) group without capture
a|b
Alternation — a or b
yes|no
\b
Word boundary
\bcat\b matches cat not cats
Regex examples to try
Match a simple email shape
Pattern
^[\w.+-]+@[\w-]+\.[\w.-]+$
Text
learner@coddy.tech
This catches the basic shape something@something.something. Real-world email validation is much more permissive than this — for forms, prefer type="email" and a server-side check.
Extract every number from a sentence
Pattern
\d+
Text
Lesson 12 has 3 tasks and 2 quizzes.
With the g flag, this finds every digit run: 12, 3, 2. \d+ is the regex equivalent of "one or more digits".
Pull an id out of a URL with a capture group
Pattern
/users/(\d+)
Text
/users/42/profile
The full match is /users/42, and the capture group (\d+) extracts just 42. Capture groups are how you actually *use* a regex match in code.
Greedy vs lazy quantifiers
Greedy
<.+>
Lazy
<.+?>
Text
<b>hello</b>
The greedy version matches the entire string <b>hello</b> because .+ grabs as much as it can. The lazy version (+?) stops at the first >, so it matches only <b> and </b>.
Common regex mistakes
Forgetting to escape special characters: ., ?, +, (, ), [, ], {, }, \, ^, $, |. When you mean them literally, prefix with \.
Writing a pattern that works for one sample but fails on realistic input with extra spaces, line breaks, or missing fields.
Using .* greedily and matching far more than intended — switch to .*? or a more specific character class.
Regex FAQ
What is regex?
Regex is short for *regular expression* — a compact pattern language for matching text. The same idea exists in almost every programming language and many editors and command-line tools.
How do I write a regex?
Start with the literal characters you want to match, then replace the variable parts with character classes (\d, \w, [abc]) and quantifiers (*, +, ?, {n,m}). Use a regex tester to iterate until the pattern matches exactly the cases you want.
What does \w mean in regex?
\w matches a word character — a letter, a digit, or an underscore. \W is the opposite (any non-word character). The exact set depends on the engine and the Unicode flag.
Why does my regex match too much?
Quantifiers are greedy by default — .* matches as much as possible. Switch to a lazy quantifier (.*?) or use a more specific character class to stop where you want.
Is JavaScript regex the same as every other regex?
The basics are the same, but engines differ. JavaScript, PCRE, Python re, Java, Go, and .NET each support slightly different flags and advanced features (lookbehind support, named groups, possessive quantifiers).
Should beginners learn regex?
Yes — gradually. Start with literals, character classes, quantifiers, anchors, flags, and capture groups. Save lookarounds, named groups, and conditional regex for later.