Regex Tester

Test and debug regular expressions against sample text with match highlighting. No signup. Ideal for developers building and refining regex patterns.

Remove Ads
Remove Ads

Result

Remove Ads

Share on Social Media:

A regex tester checks your regular expressions against sample text and highlights every match, so you can see exactly what a pattern catches before it goes into your code — free, with no account. Enter a pattern, add sample text, click Test, and the matches light up in yellow with a match count. It runs entirely in your browser, so nothing is uploaded or stored.

On this page

  1. How to Test a Regular Expression Step by Step
  2. What Regular Expressions Are and Why They Are Tricky
  3. Testing Versus Guessing at Patterns
  4. Who Needs a Regex Tester
  5. Pro Tips for Building Regular Expressions
  6. Common Regex Mistakes to Avoid
  7. Related Tools You May Need Next
  8. Frequently Asked Questions

How to Test a Regular Expression Step by Step

  1. Enter your pattern in the Regular expression box — the bare pattern only, without /…/ slashes. The placeholder shows an email pattern: \b\w+@\w+\.\w+\b
  2. Set the Flags. The box starts with g (find all matches). Add i for case-insensitive, m for multiline, s so . matches newlines — typed with no commas or spaces, e.g. gi. The g is added automatically if you leave it out.
  3. Paste sample text into the Test string box — ideally text like the real data your pattern will run against, including cases that should and should not match.
  4. Click Test. The result shows a match count ("N match(es) found.") and your text with every match highlighted in yellow.
  5. Refine the pattern and click Test again. The highlighting only updates when you click Test — typing alone changes nothing.
  6. Use the working pattern. Copy the pattern from the pattern box into your code. The result box has no Copy button — select the highlighted text manually if you need it.

Illustration of a regex tester with an email pattern, match checkmarks and highlighted results

What Regular Expressions Are and Why They Are Tricky

Regular expressions, often called regex, are patterns used to match text — a powerful, compact way to search, validate and manipulate strings based on patterns rather than exact matches. They can describe complex text structures, such as email formats, phone numbers, or specific arrangements of characters, in a concise notation. This power makes regex indispensable in programming, but it also makes them notoriously difficult to get right.

The difficulty with regular expressions is that their compact, symbolic syntax is easy to get subtly wrong. A pattern may look correct but match too much, too little, or the wrong things, and the terse notation makes such errors hard to spot by reading alone. Small mistakes have big effects, and the behaviour of a complex pattern is often not obvious until you actually run it against real text and see what it matches. That is exactly why testing against sample text, with the matches highlighted, is essential rather than optional.

This tester uses the browser's JavaScript regex engine, so it tests the flavour your web code will actually run. Worked examples — every one checked against the tool:

PatternFlagsSample textResult
\b\w+@\w+\.\w+\bgContact [email protected] or [email protected] today2 matches: [email protected], [email protected]
\d+(empty — g auto-added)order 12 and 3452 matches: 12, 345
appleiApple APPLE apple3 matches: Apple, APPLE, apple
".+" (greedy)g"one" and "two"1 match: the whole string
".+?" (lazy)g"one" and "two"2 matches: "one", "two"
\d+(?= dollars)gpay 50 dollars or 30 euros1 match: 50 only
^bgapple / banana / berry0 matches — needs the m flag
^bgmapple / banana / berry2 matches: b in banana, b in berry

An invalid pattern does not fail silently: the tool shows a toast such as "Invalid regex: Invalid regular expression: /[a-/g: Unterminated character class". An empty pattern shows "Invalid Input". The match count stops at 5,001 — the largest summary the tool ever shows is "5001 match(es) found."

Testing Versus Guessing at Patterns

ApproachTesting the patternGuessing at it
FeedbackImmediate, visual — once you click TestNone until it runs
Catches errorsYes, before codeOnly when it fails later
WorkflowRefine against examplesHope it works
ResultCorrect, understood patternError prone

The practical workflow a tester enables is to build a pattern incrementally, testing as you go. You write part of the pattern, click Test, see what it matches, adjust, and repeat, watching the highlighting until the pattern matches exactly what you intend across cases that should and should not match. This iterative testing catches the subtle errors that plague regex, letting you arrive at a correct, well-understood pattern before it ever goes into your code.

Who Needs a Regex Tester

Developers building regex. A developer builds a regular expression by testing it against sample text, refining it with feedback until it matches exactly what they intend.

People debugging patterns. Someone whose regex is not working tests it against examples to see what it actually matches, revealing the error so they can fix it.

People validating input formats. A developer creating a pattern to validate a format, like an email or code, tests it against valid and invalid examples to ensure it accepts and rejects correctly.

People learning regular expressions. Someone learning regex uses the tester to see how patterns behave against text, building understanding through immediate visual feedback.

Anyone working with text patterns. A person building any pattern to search or manipulate text tests it to confirm it works before relying on it in their code or workflow.

Laptop showing a regex tester with a pattern and highlighted matches in the sample text

Pro Tips for Building Regular Expressions

Test against realistic sample text. Use sample text like the real data your pattern will face, including cases that should match and cases that should not. Testing against realistic examples catches issues that trivial text would miss.

Include cases that should not match. A good pattern matches what you want and nothing else. Include text that should not match in your sample, to confirm your pattern is not too broad, catching things it should not.

Build the pattern incrementally. Build complex patterns step by step, clicking Test as you go, rather than writing the whole thing at once. This makes it easier to see where a part goes wrong and to refine it.

Watch for matching too much. A common regex problem is a pattern that matches more than intended, being too greedy or broad. The highlighting reveals this immediately — ".+" grabbed the whole quoted string above, while ".+?" grabbed each quoted word separately — so you can tighten the pattern.

Understand the flags you use. Regex flags change behaviour, such as case sensitivity or matching across lines. ^b matched nothing without m and matched twice with it. Ensure the flags match your intent, since they significantly affect what the pattern matches.

Type flags without commas. The placeholder reads "g, i, m, s", but typing g, i is an error — the tool rejects it as invalid flags. Type gi, with no commas or spaces.

Keep patterns as simple as possible. Simpler patterns are easier to understand, test and maintain. Avoid making a regex more complex than it needs to be, since overly intricate patterns are harder to get right and to debug later.

Common Regex Mistakes to Avoid

Not testing against text that should not match. Testing only that a pattern matches what you want, without checking it rejects what it should not, misses patterns that are too broad. Include non-matching cases in your sample to confirm the pattern is not catching things it should not.

Writing the whole pattern before testing. Building a complex regex all at once, then testing, makes errors hard to locate. Building incrementally and clicking Test after each part reveals where a problem lies.

Ignoring greedy matching. Regex patterns can match more than intended by being greedy, grabbing as much as possible. Not noticing this leads to patterns that overreach. The highlighting shows exactly what is matched, revealing greedy behaviour so you can correct it.

Forgetting about flags. Regex flags, controlling things like case sensitivity and multiline behaviour, significantly change what a pattern matches. Forgetting to set the right flags, or misunderstanding them, causes patterns to behave unexpectedly.

Wrapping the pattern in /…/ slashes. The pattern box takes the bare pattern only — slashes would be matched literally. Flags go in the Flags box, never in the pattern box.

Typing flags with commas or spaces. The code g, i is rejected as invalid flags. Type gi.

Expecting the highlighting to update as you type. It does not. Nothing highlights until you click Test — typing alone changes nothing, so click Test after every change.

Expecting a match list, capture-group display or replace function. There is none. The only output is the highlighted text plus the match count — groups such as (\d+) still work inside the pattern, but the tool never lists what each group captured.

Expecting a Copy button on the result. There is none. Copy the pattern from the pattern box, and select the highlighted text manually if you need it.

Related Tools You May Need Next

Find and Replace Text. Find text with a pattern and replace it.

Extract Emails. Pull email addresses out of a block of text.

Extract URLs. Pull web addresses out of a block of text.

Text Compare. Compare two versions of a text and spot the differences.

3D illustration of a regex tester breaking an email pattern into parts with match indicators

Frequently Asked Questions

How do I test a regular expression?

Enter your regular expression pattern and some sample text, ideally text like the real data your pattern will run against, including cases that should and should not match. Click Test and the tester highlights what your pattern matches in the text, with a match count, so you see immediately whether it matches what you intended, and only that. Adjust the pattern and click Test again, refining it until it matches exactly what you want. Once it works, copy the pattern into your code.

Is the match highlighting live as I type?

No. The highlighting appears only after you click Test, and it updates only when you click Test again after a change. Typing in the pattern or the sample text changes nothing on screen until you test. Despite the word "live" in the old description, this is a click-to-test tool, not a live-as-you-type one.

What flags can I use?

The standard JavaScript flags: g (find all matches — added automatically if you leave it out), i (case-insensitive), m (multiline, so ^ and $ match at line starts and ends), s (dot matches newlines), plus u, y and d. Type them with no commas or spaces — gi, not "g, i". The placeholder "g, i, m, s" lists the common ones, but commas in the Flags box are an error.

Why does my pattern show "Invalid regex"?

The pattern has a syntax error, and the toast includes the JavaScript engine's message — for example, [a- gives "Invalid regular expression: /[a-/g: Unterminated character class". Fix the syntax the message points to (an unclosed bracket, an unescaped special character, a bad flag) and click Test again.

Do I type /slashes/ around the pattern?

No. The pattern box takes the bare pattern only. In code you would write /pattern/gi, but here the slashes would be matched literally as part of the pattern, and the flags belong in the separate Flags box.

Why does ^ only match at the very start of my text?

Because without the m (multiline) flag, ^ matches only at the start of the whole string. Verified: ^b on three lines matched nothing with flags g, and matched twice with flags gm. Add m when your pattern should match at the start of every line.

How many matches can the tester show?

Up to 5,001. The tool stops counting after 5,001 matches, so the largest summary ever shown is "5001 match(es) found." and any further matches in a huge text are left unhighlighted.

Does it show capture groups or replace text?

No. The only output is the highlighted text plus the match count. Groups such as (\d+) still work inside the pattern, but the tool never lists what each group captured, and there is no replace function — use Find and Replace Text for replacements.

Can I copy the highlighted result?

There is no Copy button on the result. To reuse a working pattern, copy it from the pattern box; to keep the highlighted text, select it in the result box and copy it manually.

Is the regex tester free?

Yes, it is completely free with no account. It runs entirely in your browser, so your pattern and sample text are never uploaded or stored.