FormatterHQ

Regex Tester

Type a pattern, toggle flags and watch matches highlight in your test text. See every capture group, preview replacements and read a token-by-token explanation.

Loading tool…
Ready.

How to use the Regex Tester

  1. Enter your pattern in the Regular expression field (with or without the surrounding slashes).
  2. Toggle the flags you need — g, i, m, s, u or y.
  3. Paste or type sample text in the test area; matches are highlighted as you type.
  4. Check the match list for positions, numbered groups and named groups.
  5. Add a replacement such as $2/$1 or $<name> to preview the result of a replace.

Online regex tester for JavaScript regular expressions

This regex tester runs your pattern against sample text as you type, using the same RegExp engine that powers your browser and Node.js. Matches are highlighted in place, every capture group is listed with its value, and a replace preview shows exactly what String.prototype.replace would return. You can fix a pattern here before it ever reaches your code.

What the tester shows you

  • Pattern field with flag toggles. Type a bare pattern or paste a literal like /\d+/gi; the flags after the closing slash are picked up automatically.
  • Live highlighting. Each match is marked in the test text, so greedy quantifiers that swallow too much are obvious at a glance.
  • Match list. Every match with its start and end offset, followed by numbered groups and, where you used (?<name>…), the group name.
  • Replace preview. The full text after replacement, refreshed as you edit the pattern, the text or the replacement.
  • Explanation panel. A token-by-token breakdown of the pattern in plain English.
  • Cheat sheet. Click a token such as \b, (?=…) or {2,5} to insert it into your pattern.

Example: named groups and a replacement

With the pattern (?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+), the flag g and the text ann.lee@example.com, bob@test.co.uk, the match list shows each match with its offsets and its groups by name:

1  ann.lee@example.com  0–19
   user    ann.lee
   domain  example.com
2  bob@test.co.uk  21–35
   user    bob
   domain  test.co.uk

Replacements use JavaScript syntax. Reformatting ISO dates with (\d{4})-(\d{2})-(\d{2}) and the replacement $2/$3/$1 turns Due 2024-07-15 and 2024-08-01 into Due 07/15/2024 and 08/01/2024. You can also use $& for the whole match, $<name> for a named group and $$ for a literal dollar sign. Typing \n or \t in the replacement inserts a real line break or tab.

Flags explained

FlagNameEffect
gglobalFind every match instead of stopping at the first one.
iignoreCaseLetters match regardless of case.
mmultiline^ and $ also match at the start and end of each line.
sdotAll. also matches line breaks.
uunicodeTreats surrogate pairs such as emoji as one character and enables \p{…} property escapes.
ystickyOnly matches at the exact position where the previous match ended.

Common regex errors and how to fix them

  • Only one match appears. Without g the tester reports the first match only and says so in the status line. Turn on g to see them all.
  • "Invalid regular expression: Unterminated group". A ( has no closing ). The error text comes straight from the JavaScript engine, so it matches what your app would throw.
  • The match runs too far. <.*> on <b>hi</b> matches the whole string because * is greedy. Use the lazy .*? or a negated class like [^>]*.
  • ^ matches only once. In multi-line text, add the m flag so anchors work per line.
  • A pattern from PHP or Python fails. JavaScript has no possessive quantifiers, no \A or \Z and no inline modifiers like (?i). Paste the pattern into the regex explainer to spot PCRE-only tokens.
  • Special characters in user input. If you build a pattern from literal text such as $19.99, run it through the regex escape tool first so . and $ lose their special meaning.

To check a pattern from the other direction, the random data from regex generator produces sample strings that match it, which is a quick way to find inputs you did not expect to be accepted.

Privacy

Your pattern and test text are evaluated by the JavaScript engine in your own browser. Nothing is uploaded, so you can safely test against log lines, customer records or other data you would not paste into a server-side tool.

Test a regex in Python

In Python, test a pattern with the re module: finditer() yields every match with its span and groups. This page runs the JavaScript engine, and two syntax differences cause most of the confusion when a pattern moves between the two. Python writes named groups as (?P<name>…) and rejects the JavaScript form (?<name>…), and replacements use \1 or \g<name> where JavaScript uses $1 and $<name>. Also remember that re.match() only matches at the start of the string; use search() or finditer() to scan.

import re

pattern = re.compile(r"(?P<user>[\w.+-]+)@(?P<domain>[\w-]+(?:\.[\w-]+)+)")
text = "ann.lee@example.com, bob@test.co.uk"

for match in pattern.finditer(text):
    print(match.span(), match.group(0), match.groupdict())

print(pattern.sub(r"\g<user> at \g<domain>", text))

Change (?P< to (?< and the tester above reports the same two matches, at offsets 0–19 and 21–35.

Frequently asked questions

Which regex flavor does this tester use?
It uses the JavaScript (ECMAScript) RegExp engine built into your browser, so results match what Chrome, Firefox, Safari and Node.js do. Features that exist only in PCRE, such as possessive quantifiers or atomic groups, are reported as invalid syntax.
Does it support named capture groups and lookbehind?
Yes. Named groups written as (?<name>…) appear with their name in the match list, and you can reference them in a replacement with $<name>. Lookbehind (?<=…) and (?<!…) work in all current browsers.
Why does my regex find only the first match?
The global flag is off. Without g, JavaScript stops after the first match, and the tester notes this in its status message. Enable g to list every match.
Can I test multi-line text?
Yes. Paste as many lines as you like. Enable m if you want ^ and $ to match at each line, and s if you want . to cross line breaks.
How many matches can it show?
The tester collects up to 5,000 matches to keep the page responsive and says so in the status line when that cap is reached; the match list itself shows the first 500 and notes how many more there are. Zero-length matches, such as those produced by a pattern like \b or x*, are handled without getting stuck in an endless loop.

Last updated October 3, 2026

Guides

Related tools

API Tester (REST Client) Send GET, POST, PUT, PATCH and DELETE requests to REST APIs from your browser and inspect status, headers and pretty-printed JSON. JavaScript Tester Run JavaScript online and see console.log, warnings, errors and tables instantly in a safe, sandboxed browser console. JSONPath Tester Test JSONPath expressions online against your JSON. Supports filters, wildcards, recursive descent and slices, returning values or paths. Random Data from Regex Generate random strings that match a regular expression — ideal for test data such as IDs, codes and formats. Regex Cheat Sheet Interactive regex cheat sheet: anchors, classes, quantifiers, groups, lookarounds, flags and Unicode, with clickable examples and a flavour table. Regex Escape Escape special characters so any text can be matched literally inside a regular expression in JavaScript, PCRE, Python or Java. SemVer Checker & Range Tester Validate, compare and sort semantic versions and test them against npm-style ranges like ^1.2.0, ~2.3 or >=1.0 <2. Snowflake ID Decoder Convert Twitter/X, Discord, Instagram and other Snowflake IDs to timestamps and show worker, process and sequence bits. Time Sheet Calculator Add up weekly work hours from start and end times with breaks. Calculates overtime per day or week and optional gross pay. TOTP / 2FA Code Generator Generate live TOTP 2FA codes from a Base32 secret or otpauth:// URI, create new secrets and QR codes for authenticator apps. ULID Decoder Decode ULIDs to their embedded timestamp and random part, and convert between ULID and UUID formats. Un-Google Link Remove Google redirect wrappers (google.com/url, AMP, image results) and tracking parameters to get the real destination URL.