Toolbox Hub
All Tools

Regex Tester

Test regular expressions

Test regular expressions Runs locally in your browser

About the

The Regex Tester runs a JavaScript regular expression against your own sample text and highlights every match as you type, so you can watch a pattern succeed or fail instead of guessing. Alongside the highlights it lists each match with its start position and its capture groups, which is the part that actually tells you whether group 2 is the value you wanted or an empty string. Three mistakes cause most broken regexes, and all three are visible here: a greedy quantifier quietly swallowing more text than intended, an unescaped dot matching anything, and a missing global flag that stops the search after the first hit.

Where people use the

  • Debugging a log-parsing pattern against a handful of real log lines.
  • Working out a phone or postal-code rule before wiring it into a form.
  • Extracting order numbers or IDs from a pasted block of text.
  • Learning how quantifiers behave by changing one character and watching the highlights move.

How to use the

  1. 1

    Paste the text you want to test

    Use a real sample rather than an invented one. The edge cases in your actual data are what break the pattern, so include a line that should not match too.

  2. 2

    Write the pattern

    Enter the expression without the surrounding slashes, for example [a-z]+ rather than /[a-z]+/. Flags are separate toggles.

  3. 3

    Turn flags on or off

    g finds every match instead of stopping at the first, i ignores case, m makes anchors work per line, s lets a dot span newlines, u enables full Unicode mode and y anchors matches to lastIndex.

  4. 4

    Read the match table

    Each result shows the matched text, its character offset and every capture group. An unexpected empty group usually means an optional quantifier matched nothing.

  5. 5

    Copy the finished pattern

    When the highlights look right, copy the expression and paste it into your code, remembering to carry the flags across as well.

Tips and best practices

  • Test one rule per pattern. A regex doing three jobs is unreadable and impossible to debug.
  • Include a line that must not match and confirm it stays unhighlighted.
  • Prefer named groups such as year, month, day over numbered ones, so the pattern still means something when you return to it next month.

Frequently asked questions

Which regex flavour does this use?

JavaScript, via the browser's own RegExp engine. Syntax is close to PCRE and Python's re module, but not identical. Named groups, lookahead, lookbehind and Unicode property escapes all work in current browsers.

Why does my pattern match far more text than I expected?

Because quantifiers are greedy by default. Something like .* or [0-9]+ will consume as much as it can while still allowing the rest of the pattern to match. Add a question mark to make it lazy, so .*? or [0-9]+? stops at the first opportunity.

Why do I only get one result?

The global flag is off. Without g, the engine returns the first match and stops. Toggle g to collect every match in the input.

Why does my anchor not work on the second line?

By default the caret and dollar anchors refer to the start and end of the whole string, not each line. Enable the m flag to make them line-aware.

Is my test data sent anywhere?

No. Matching happens in your browser with the built-in RegExp object. Nothing is uploaded, which is why you can safely paste real log lines or configuration fragments.

Can I use this to validate input on a form?

You can develop the pattern here, but always validate again on the server. Client-side regex is a convenience for the user, never a security control, because it can be skipped entirely.

Related Tools