Regex Tester
Quick reference
. | any character |
\d \w \s | digit / word char / whitespace |
\D \W \S | negated of the above |
[abc] [^abc] | set / negated set |
a|b | a or b |
* + ? | 0+ / 1+ / 0 or 1 |
{2} {2,5} | exactly 2 / 2 to 5 |
^ $ | start / end |
\b | word boundary |
(...) (?:...) | capture / non-capture group |
Share on Social Media:
Regex tester: write a pattern and see what it matches in real time
A regex tester lets you type a regular expression on one side, paste your sample text on the other, and watch every match highlight as you type. This online regex tester explains why a pattern hits or misses, lists captured groups, and shows the flags in play, so you stop guessing and start seeing exactly what your expression does. It runs in your browser with no signup and is built for quick iteration when a pattern almost works but not quite.
Regular expressions power search-and-replace, form validation, log parsing, and data extraction in nearly every language. The trouble is they fail silently: a stray + or a forgotten escape and your pattern quietly matches nothing. A regex tester closes that feedback loop, turning trial-and-error into a few quick edits with instant visual confirmation across JavaScript, Python, Java, and C# style syntax.
How to use the regex tester
- Enter your pattern. Type the expression into the regex field, without the surrounding slashes unless your flavor uses them.
- Set the flags. Toggle global, case-insensitive, multiline, and dotall to control how the engine scans.
- Paste your test text. Drop in real sample data so matches reflect production conditions.
- Read the matches. Highlighted spans show full matches; the match list shows each capture group by number or name.
- Iterate. Adjust the pattern and watch the highlights update live until it matches exactly what you intend.
How regular expressions work
A regex is a small program describing a set of strings. The engine reads your pattern left to right and tries to match it against the text, character by character, backtracking when a branch fails. Most characters match themselves, while metacharacters like ., *, and [] have special meaning. To match a literal metacharacter, escape it with a backslash, so a literal dot is \. and a literal plus is \+.
For example, the pattern \b\d{3}-\d{4}\b matches a 7-digit phone fragment like 555-1234: \b is a word boundary, \d{3} is exactly three digits, the hyphen is literal, and \d{4} is four more digits. Wrapping part of a pattern in parentheses creates a capture group you can extract or reuse.
| Token | Matches | Example |
|---|---|---|
. | Any character except newline | a.c matches abc |
\d \w \s | Digit, word char, whitespace | \d+ matches 2026 |
* + ? | 0+, 1+, 0 or 1 repetitions | ab+ matches abbb |
{n,m} | Between n and m repetitions | a{2,4} matches aaa |
[abc] [^abc] | Character class / negated class | [A-Z] matches one capital |
^ $ | Start and end of line or string | ^Hi matches a leading Hi |
\b | Word boundary | \bcat\b avoids category |
(...) (?:...) | Capturing / non-capturing group | (\d{4}) captures a year |
| | Alternation (OR) | cat|dog matches either |
Flags and flavor differences
Flags change how the whole pattern behaves. The most common are global (find all matches, not just the first), case-insensitive, multiline (so ^ and $ match at line breaks), and dotall (so . also matches newlines). Each language exposes them slightly differently, which is why the same pattern can behave inconsistently across stacks.
| Concern | JavaScript | Python | Java / C# |
|---|---|---|---|
| Case-insensitive | /.../i | re.I | (?i) or flag |
| Find all | /.../g | re.findall | Matcher.find() loop |
| Dotall | /.../s | re.S | Pattern.DOTALL |
| Named group | (?<y>\d+) | (?P<y>\d+) | (?<y>\d+) |
| Lookbehind | Supported (modern) | Supported | Supported |
Common mistakes
- Greedy quantifiers eating too much.
.*grabs as much as possible; use the lazy form.*?when you want the shortest match. - Forgetting to escape metacharacters. To match a literal dot or slash, write
\.or\/, not a bare character. - Missing the global flag. Without it, a JavaScript regex returns only the first match and replace touches one occurrence.
- Anchoring incorrectly.
^and$match line edges only with the multiline flag; otherwise they bound the whole string. - Catastrophic backtracking. Nested quantifiers like
(a+)+can hang on certain inputs; simplify the pattern.
Tips and related tools
Build patterns incrementally: match the simplest case first, then tighten with anchors and groups while watching the live highlights. When your regex extracts data into structured form, clean it with the JSON Formatter, confirm it with the JSON Validator, explore the result in the JSON Viewer, or convert it with JSON to XML for systems that expect XML. Find more developer utilities in the development tools hub.
Frequently asked questions
What is a regex tester? It is a tool that lets you write a regular expression, paste sample text, and see matches and capture groups highlight in real time so you can debug the pattern quickly.
Do I include the slashes in the pattern? In JavaScript style, the slashes delimit the pattern and flags, but in most testers you type the pattern alone and toggle flags separately. Match the convention of your target language.
What is the difference between greedy and lazy matching? Greedy quantifiers like .* match as much as possible, while lazy quantifiers like .*? match as little as possible. Use lazy when you want the shortest span.
How do I capture part of a match? Wrap the part you want in parentheses to create a capture group, then read it by index or by name with (?<name>...).
Why does my pattern match nothing? Common causes are an unescaped metacharacter, a missing flag, or anchors that do not align with your text; the live highlighting helps you pinpoint where it breaks.
Does regex syntax differ between languages? The core syntax is shared, but flags, named groups, and lookbehind support vary across JavaScript, Python, Java, and C#. Test against the flavor you will deploy.
What does a word boundary do? \b matches the position between a word character and a non-word character, so \bcat\b matches the word cat but not category.
Is my test data private? Yes. The regex tester runs entirely in your browser, so neither your pattern nor your sample text is uploaded.
🔗 Relevant Tools
Link to this tool
Found this tool useful? Add it to your website or blog with one of these snippets.
Add the live, working tool to your own page:
Leave a comment
Comments go straight to our team — they are not published on the site.