Regex Tester

Matches found—
First match—
Capture groups—

How Regex Tester is calculated: Real JavaScript RegExp testing: the pattern runs against your sample text with the flags you pick. Matches are listed with their capture groups; an invalid pattern reports its error instead of failing silently.

What is a regex tester?

A regex tester is a workbench for regular expressions — the small pattern language used to find, check, and pull apart text. You type a pattern, you type some sample text, and the tester shows you exactly what the pattern matches: every match, how many there are, and what each capture group caught. It is how developers write patterns without guessing.

The default example on this page shows the idea at once. The pattern \d+ means one or more digits, and the sample text is Order 42 shipped on 2026-11-15, tracking 98765. The tester finds 5 matches: 42, 2026, 11, 15, and 98765. The first match is 42, and there are 0 capture groups, because the pattern has no parentheses in it.

Regular expressions are used everywhere text is processed: checking that an email address looks right, pulling order numbers out of a message, finding dates in a log file, or validating a username on a sign-up form. The patterns are powerful and famously easy to get slightly wrong, which is why testing them against real text before using them matters so much.

This tester runs real JavaScript regular expressions — the same RegExp engine your browser uses — so a pattern that works here works the same way in your code. It is not a simplified simulation. What you see is what the engine does, including the cases where a pattern matches nothing at all.

How this regex tester works

The tester builds a RegExp from your pattern and your chosen flags, then runs it against the sample text. With the g flag, it finds every match, one after another, and lists them in the output box numbered in order. Without the g flag, it stops at the first match. The match count, the first match, and the number of capture groups in that first match appear in the results above.

Capture groups are the parts of a pattern wrapped in parentheses, and they are the reason regex is useful for more than just finding things. The pattern ([A-Z][a-z]+) (\d+) has two groups: a capitalised word and a number. Against the default sample text it matches once — Order 42 — and the output shows the groups separately: Order and 42. That is how you pull structured pieces out of unstructured text.

Flags change what the engine does. The i flag ignores upper and lower case, so a pattern written in lower case matches capitalised words too. The m flag makes the start and end anchors work per line instead of per text, which matters when your sample has several lines. The flags dropdown offers the combinations people use most, with the g flag as the default because finding all matches is usually the point.

An invalid pattern does not fail silently. If you type a lone opening parenthesis, the tester reports the error — Invalid pattern: Unterminated group — with 0 matches, instead of showing nothing and leaving you to wonder. Regex errors are usually a missing bracket or an unescaped character, and seeing the engine's own message is the fastest way to find them.

The numbers: matches, first match, and groups

The three results tell you what happened at a glance. Matches found is the count of matches — 5 for the default pattern and text. First match is the text of the first match, 42 in the default, which is useful when you only care about what was found first. Capture groups is the count of parenthesised groups in the first match — 0 for \d+, 2 for the capitalised-word pattern.

The output box lists every match in order, with its groups. For the default, the list reads 1. 42, 2. 2026, 3. 11, 4. 15, 5. 98765 — five numbers pulled out of a sentence that also contains words, commas, and hyphens. That list is the real result of the test: the count tells you how many, and the list tells you what.

A match count of zero is information too. It means the pattern does not occur in the sample, which usually means one of two things: the pattern is wrong, or the sample does not contain what you expected. Change the sample to text you know contains the target, and if the count is still zero, the pattern is the problem. Testing against a sample you control is what makes the count trustworthy.

Watch the group count when you write patterns with parentheses. Every pair of parentheses is a group, including ones you added only to group alternatives, like (cat|dog). If the group count is higher than the pieces you wanted to capture, some of those groups are structural, and the pieces you wanted are numbered differently than you assumed.

A worked example: numbers, words, and groups

Start with the default: pattern \d+, flags g, sample Order 42 shipped on 2026-11-15, tracking 98765. The tester finds 5 matches. Note what it does not match: the words Order, shipped, on, and tracking, the comma, and the hyphens inside the date. The pattern asks only for runs of digits, and that is all it returns — including the date split into its three parts, 2026, 11, and 15.

Change the pattern to [A-Z][a-z]+ with no flags. Now there is 1 match: Order. The pattern asks for a capital letter followed by lower-case letters, and only the first word qualifies. Without the g flag the tester stops after that first match, which is the right behaviour when you only need to know whether the pattern occurs at all.

Now try ([A-Z][a-z]+) (\d+) with the g flag. There is 1 match again — Order 42 — but this time the output shows the groups: Order and 42. The parentheses did not change what matched; they labelled the pieces inside the match so you can use them separately. That is the difference between finding text and extracting data from it.

Finally, break it on purpose: type a single ( as the pattern. The tester reports 0 matches and the error message, Unterminated group. Fix it by closing the parenthesis, and the matches come back. Seeing the error instead of a blank result is what makes a tester faster than guessing in your code.

Who tests regex, and why

Developers test patterns before they ship them, because a wrong pattern fails in ways that are hard to see later. A validation pattern that rejects valid email addresses loses sign-ups silently. A pattern that extracts order numbers but misses some formats loses data silently. Testing against real sample text first catches both before anyone else sees them.

Data analysts use a tester to pull structure out of messy text: order numbers from messages, dates from logs, codes from filenames. The pattern is written once, tested against a few dozen samples, and then used on thousands of lines. The tester is where the pattern is proved before it meets the real data.

Writers and editors use regex to clean up documents: finding double spaces, normalising date formats, or checking that every heading follows the same pattern. A tester shows exactly what a find-and-replace pattern would touch before it touches anything, which is the difference between a careful edit and a ruined document.

Learners use a tester to build intuition. Regular expressions look cryptic until you watch a pattern match real text, change one character, and watch the matches change. The immediate feedback — 5 matches, then 1, then 0 — teaches faster than any reference page, because the pattern's behaviour is visible instead of imagined.

Regex tester vs regex generator

A tester and a generator solve opposite halves of the same problem. A tester takes a pattern you already have and shows you what it does. A generator takes a description of what you want — an email address, a date, a phone number — and writes the pattern for you. If you know what you need but not how to write it, start with the generator; if you have a pattern and need to check it, start here.

The two tools work well together. Generate a pattern for an email address, then paste it into this tester with a few sample addresses — a valid one, an invalid one, an edge case — and watch which ones match. The generator gives you a starting point; the tester proves whether that starting point is right for your data.

For building patterns from scratch, the generator's custom builder is the middle ground: pick a character class and a quantifier, and it assembles the pattern. Paste that into the tester, and the loop is complete — build, test, adjust, test again. Most patterns take three or four rounds of that loop before they are right.

For everything else text-shaped, the site has companions: a word counter for counting what a pattern found, a text formatter for cleaning text up before testing, a character counter for counting characters when a limit is measured that way, and a text diff checker for comparing two versions of a text side by side.

Common regex mistakes

The most common mistake is forgetting that some characters are special. A dot means any character, not a literal dot, so a pattern meant to match a web address will also match nonsense. To match a literal dot, write it as \. — and test it, because the difference between matching example.com and matching exampleXcom is one backslash.

Second: greedy matching. The pattern <.+> against a line with two tags matches from the first opening bracket to the last closing bracket, swallowing everything in between, because + takes as much as it can. The fix is usually to make it lazy, <.+?>, or to exclude the closing character, <[^>]+>. Both are easy to check in the tester by watching the match list.

Third: forgetting the flags. A pattern without the g flag finds only the first match, and a pattern without the i flag misses capitalised words. If your match count is 1 when you expected 5, check the flags before you rewrite the pattern — the pattern is often fine and the flag is the problem.

Fourth: testing against too little text. A pattern that works on one sample can fail on the next, because real text is messier than the example in your head. Test against several samples, including the awkward ones — empty strings, text with no match, text with the match in an unexpected place — before you trust a pattern in production.

How to use this regex tester

Type your pattern into the first box. The default, \d+, is already there, finding the 5 numbers in the sample text. Change it and the results update instantly as you type — there is no button to press, so you can watch the match count change with every character you add or remove.

Pick your flags from the dropdown. The g flag finds all matches and is the default. No flags means first match only. Add i to ignore case, or m to make anchors work per line. The results and the match list update with the flags, so you can see immediately what each flag changes.

Paste or type your sample text into the large box. Use real text from your own data, not just the default — a pattern is only as trustworthy as the samples it has passed. Try the awkward cases too: text with no match, text where the match sits at the very start or end.

Everything runs in your browser. Your pattern and your sample text never leave your device, are never uploaded, and are never stored. You can test patterns against private logs, customer messages, or proprietary data without worrying about where the text goes — it goes nowhere, and closing the page removes it.

Frequently Asked Questions

Five: 42, 2026, 11, and 15 from the date, and 98765 from the tracking number. The pattern matches runs of digits only, so the words, commas, and hyphens are ignored, and the date 2026-11-15 is split into its three numeric parts.

With the g flag the tester finds every match in the text; without it, it stops after the first. The default pattern finds 5 matches with g, and the pattern [A-Z][a-z]+ with no flags finds just 1 — the word Order. Use g when you want them all, and no flags when you only need to know whether the pattern occurs.

Capture groups are the parts of a pattern wrapped in parentheses, and they let you pull pieces out of a match separately. The pattern ([A-Z][a-z]+) (\d+) matches Order 42 once, with 2 groups: Order and 42. Without the parentheses you would know the text matched, but you could not use the word and the number separately.

The tester reports the error instead of failing silently — for example, a lone ( gives 0 matches and the message Unterminated group. Regex errors are usually a missing bracket or an unescaped character, and seeing the engine's own message is the fastest way to find and fix them.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.