ToolForge
Advertisement

Regex Tester

Test regular expressions with real-time matching

Written by toolforge.websiteLast reviewed How we build and check these tools

Regex Tester tool

//

Regex Tester: key facts

What it does
Test regular expressions with real-time matching
Category
Developer Tools
Cost
Free, with no account, sign-up, or install.
Your data
Runs entirely in your browser — the files and text you enter are never uploaded to a server.
Last reviewed
. Report an incorrect result.
Advertisement

Understanding the Regex Tester

Regular expressions are powerful and famously unforgiving — a single misplaced character can change everything a pattern matches. The Regex Tester gives you a live workbench: type a pattern, paste some sample text, and watch every match light up instantly.

It mirrors how people actually debug regex. A developer validating an email or phone format pastes a dozen real examples to see which ones slip through. Someone writing a log parser tweaks a capture group and immediately sees whether it grabs the timestamp correctly. Support engineers use it to build the search-and-replace pattern they will paste into another tool, confident it does what they expect first.

Matches are highlighted directly in your test text, and each one is broken out below with its capture groups, position, and length — so you are not just told "3 matches", you can see exactly where and what they are.

Getting a result

  1. Type your pattern into the expression field (the slashes around it are shown for you).
  2. Set flags either by typing them in the flags box or by clicking the g, i, m, s, u, and y toggle buttons.
  3. Paste the text you want to test into the "Test Text" area.
  4. Watch matches highlight in yellow as you type; the header shows the live match count.
  5. Scroll the match details to inspect each capture group, index, and length, then click "Copy Regex" to copy your pattern in /pattern/flags form.

JavaScript's regex flavour, and the flags

Your pattern is compiled with the browser's own regular expression engine, so what you see here is exactly what the same pattern does in JavaScript. Matches are collected and highlighted against the test text, and an invalid pattern reports the engine's own syntax error.

The flags are toggles rather than syntax, and they change behaviour substantially. The global flag continues past the first match to find all of them; without it, the tool reports one match and stops. Case-insensitive matching, multiline mode — which changes what the start and end anchors mean — and dot-matches-newline are the others in common use.

Regex flavours differ more than people expect, so a pattern copied from documentation for another language may behave differently or not compile at all. Lookbehind, named groups, and Unicode property escapes are the usual points of divergence.

  • Without the global flag, only the first match is reported, which is the most common cause of confusion here.
  • In multiline mode the caret and dollar anchors match at each line boundary rather than only at the ends of the input.
  • A pattern that fails to compile reports the engine's error rather than silently matching nothing.

Reasons to use it here

  • It uses your browser's native JavaScript RegExp engine, so what you test here behaves exactly like the regex in your JavaScript code — no dialect surprises.
  • All six JavaScript flags (g, i, m, s, u, y) are available as one-click toggles, so you do not have to remember which letter does what.
  • Matches are highlighted in place and each is itemized with its capture groups, start index, and length, which makes debugging groups far easier than a bare match count.
  • Everything runs locally and updates in real time — paste sensitive log data without it ever being uploaded.

Catastrophic backtracking, and what not to parse

Nested quantifiers over overlapping character classes can make matching time grow exponentially with input length. A pattern of the shape (a+)+b against a long run of a characters is the standard demonstration: the engine explores an enormous number of ways to divide the input before concluding there is no match. On a server, a pattern like that applied to user input is a denial-of-service vector, and it has caused real outages.

Keeping quantifiers from overlapping, anchoring patterns where possible, and preferring specific character classes to the dot all reduce the risk. Testing against deliberately awkward input — long strings that almost match — is the practical check.

The other lesson is about scope. Regular expressions cannot parse recursive structures, so HTML, JSON, and source code are the wrong problems for them, however tempting a quick pattern looks. Use a parser for anything nested. Email addresses deserve a specific mention: the fully compliant pattern is monstrous and still does not establish that an address receives mail, so a permissive check plus a confirmation email is the sensible approach.

Frequently Asked Questions

Which regex flavor does this tester use?

It uses the JavaScript (ECMAScript) regular expression engine built into your browser. Patterns that rely on features from other flavors — such as PCRE lookbehind in older engines or named groups syntax differences — may behave differently than in Python, PHP, or Java.

What do the g and m flags actually do?

The "g" (global) flag finds all matches instead of stopping at the first. The "m" (multiline) flag makes the ^ and $ anchors match at the start and end of each line rather than only the whole string. You can toggle both with the flag buttons and watch the matches change.

Why is only the first match highlighted?

Without the global flag, a regex returns only the first match. Turn on the "g" flag (or click the g button) and the tester will find and highlight every match in your text.

My pattern shows an error — what is wrong?

The tester reports the exact error from the RegExp engine, usually a syntax problem such as an unclosed bracket or group, or an invalid escape sequence. Fix the highlighted issue in the pattern and matching resumes automatically.

Related Tools

Advertisement
Buy Me a Coffee