Skip to content
Free tool · no signup

Regex Tester

Test and debug regular expressions instantly. Type a pattern, toggle the flags, and watch every match highlighted live in your test string — with full capture groups, match indices and a live replace preview. It uses your browser's native JavaScript (RegExp) engine, so everything runs in your browser; nothing is uploaded.

Regular expression/…/g
//g
Test string52 chars
Matches in context3 matches
Invoices due: 2026-01-15, 2026-02-28 and 2026-12-03.
Match details
#12026-01-15
index 14–24
$12026
$201
$315
#22026-02-28
index 26–36
$12026
$202
$328
#32026-12-03
index 41–51
$12026
$212
$303
Replaceuse $1, $<name>, $&
Result preview
Invoices due: 15/01/2026, 28/02/2026 and 03/12/2026.

Everything runs locally in your browser with the native JavaScript RegExp engine — your pattern and test string are never uploaded. Input length and match time are capped so a pathological pattern can't run away with the page.

TL;DR

What this tool is

  • A free, in-browser regular-expression tester: type a pattern, pick flags, and see every match highlighted live in your test string as you type.
  • Inspect each match in detail — its exact start/end index, numbered capture groups ($1, $2, …) and named groups (<name>), with empty vs. undefined groups shown clearly.
  • Toggle all six ECMAScript flags — g (global), i (ignore case), m (multiline), s (dotAll), u (unicode) and y (sticky) — and watch results update instantly.
  • A live replace preview applies your replacement string ($1, $<name>, $& and friends) to the test text, so you can build a find-and-replace before using it anywhere.
  • Everything runs client-side on the browser’s native JavaScript RegExp engine — nothing is uploaded — and input length and match time are capped to stay safe on pathological (ReDoS-prone) patterns.

What is a regular expression?

A regular expression (regex) is a compact pattern that describes a set of strings. Rather than searching for one fixed word, you describe the shape of what you want — "a four-digit year", "an email-like token", "a line starting with ERROR" — and the engine finds every piece of text that fits. Patterns combine literal characters with metacharacters: character classes like \d and \w, quantifiers like + and {2,4}, anchors ^ and $, groups in parentheses, and alternation with |.

This runs in your browser (ECMAScript flavor)

The tester compiles your pattern with the browser's native RegExp, so the behavior is exactly ECMAScript (the same regex you get in JavaScript and Node.js). Most syntax is portable, but ECMAScript has no inline modifiers such as (?i), no possessive quantifiers or atomic groups, and sets flags outside the pattern. If you are targeting PCRE, Python's re, Go's RE2 or Java, double-check any exotic construct against that engine.

Token cheat-sheet

  • .any character (except newline, unless the s flag is set)
  • \d \Da digit 0–9 / a non-digit
  • \w \Wword char [A-Za-z0-9_] / a non-word char
  • \s \Swhitespace / non-whitespace
  • [abc] [^abc]one of a, b, c / anything except a, b, c
  • [a-z]a range — any lowercase letter
  • ^ $start / end of string (or of a line with the m flag)
  • \b \Ba word boundary / a non-boundary
  • * + ?zero-or-more / one-or-more / optional
  • {2} {2,} {2,5}exactly 2 / 2 or more / between 2 and 5
  • *? +? ??lazy (non-greedy) versions of the quantifiers
  • a|balternation — match a or b
  • ( … )capturing group (numbered $1, $2, …)
  • (?<name> … )named capturing group ($<name>)
  • (?: … )non-capturing group (grouping only)
  • (?= … ) (?! … )lookahead: followed by / not followed by
  • (?<= … ) (?<! … )lookbehind: preceded by / not preceded by
  • \1 \k<name>backreference to an earlier group

The flags

  • gglobal — find all matches, not just the first
  • iignore case
  • mmultiline — ^ and $ match at every line break
  • sdotAll — . also matches newline characters
  • uunicode — code-point mode, enables \u{…} and \p{…}
  • ysticky — match only from the engine’s lastIndex

Capture groups and replacement

Parentheses create a capture group whose matched text is numbered left to right — $1, $2, and so on — so you can pull sub-parts out of a match or reuse them in a replacement. For example, the pattern (\d{4})-(\d{2})-(\d{2}) with the replacement $3/$2/$1 rewrites 2026-01-15 as 15/01/2026. Named groups (?<year>\d{4}) are referenced as $<year>, and (?:\u2026) groups without capturing. The match list below shows every group and its index.

Security note — ReDoS: a regular expression run on untrusted input can be a denial-of-service vector. Patterns with nested or overlapping quantifiers — the classic (a+)+$ or (.*a){20} — can trigger catastrophic backtracking, where a few dozen crafted characters pin a CPU core for seconds or longer. On a server handling attacker-controlled input, one request can stall the whole service. Prefer simple, anchored patterns, avoid nesting quantifiers over the same characters, cap input length, and consider a linear-time engine (RE2) for untrusted data. This tester matches only a capped prefix of the test string and gives its match loop a time budget — but a regex runs synchronously, so a single pathological match on huge input can still be slow. All testing stays in your browser, so trying a risky pattern never reaches a server.

Frequently asked questions

What is a regular expression?

A regular expression (regex or regexp) is a compact pattern that describes a set of strings. Instead of searching for one fixed word, you describe the shape of what you want — "a four-digit year", "an email-like token", "a line that starts with ERROR" — and the regex engine finds every piece of text that fits. Patterns are built from literal characters plus metacharacters: character classes like \d (digit) and \w (word character), quantifiers like * (zero or more), + (one or more) and {2,4} (between two and four), anchors like ^ and $, groups in parentheses, and alternation with |. Regular expressions are used everywhere text is processed: search-and-replace in editors, input validation, log parsing, data extraction and scanning rules.

What regex flavor does this tester use?

It uses your browser’s native JavaScript engine, so the flavor is ECMAScript (the same RegExp you get from new RegExp() or a /pattern/ literal in JS and Node.js). Most common syntax — character classes, quantifiers, anchors, groups, alternation, backreferences, lookahead and (in modern engines) lookbehind and named groups — behaves the same across flavors, but some features differ. ECMAScript has no inline modifiers like (?i), no possessive quantifiers or atomic groups, no \A/\Z anchors, and no recursion. Flags are set outside the pattern (the g, i, m, s, u, y toggles here). If you are targeting PCRE, Python’s re, Go’s RE2 or Java, verify any exotic construct against that engine — this tool reflects what the browser does.

What do the g, i, m, s, u and y flags mean?

They change how the pattern is applied. g (global) finds every match instead of stopping at the first — it is what lets this tester list all matches and replace all occurrences. i (ignore case) makes letters match regardless of case. m (multiline) makes the ^ and $ anchors match at the start and end of each line rather than only the whole string. s (dotAll) makes the dot . also match newline characters. u (unicode) treats the pattern as a sequence of Unicode code points and enables \u{...} escapes and \p{...} property classes. y (sticky) anchors each match attempt to the engine’s lastIndex, so matches must be contiguous from that position. Toggle them in the tester and the match list updates immediately.

What are capture groups and backreferences?

Parentheses ( ) in a pattern create a capture group: the text matched inside them is remembered and numbered left to right ($1, $2, …), so you can pull sub-parts out of a match or reuse them in a replacement (e.g. turning 2026-01-15 into 15/01/2026 with $3/$2/$1). Named groups, written (?<year>\d{4}), capture to a name instead, referenced as $<year> in a replacement. A backreference like \1 inside the pattern matches the same text an earlier group captured. If you only want to group for precedence or alternation without capturing, use a non-capturing group (?:…). This tester shows every numbered and named group for each match, and marks a group that did not participate as "undefined".

Can a regular expression be a security risk?

Yes — the classic one is ReDoS (Regular-expression Denial of Service), caused by catastrophic backtracking. A pattern with nested or overlapping quantifiers, such as (a+)+$ or (.*a){20}, can take exponential time on certain inputs: a few dozen characters of the wrong shape can pin a CPU core for seconds, minutes or effectively forever. If that regex runs on attacker-controlled input in a request handler, one crafted string can stall or take down the service. Mitigations: prefer simple, anchored patterns; avoid nesting quantifiers over the same characters; set input-length limits; and consider a linear-time engine like RE2 for untrusted input. This tester defends itself by matching only a capped prefix of the test string, limiting how many matches it collects, and giving the global match loop a wall-clock time budget — but note that JavaScript runs a regex synchronously, so a single pathological match on a huge string can still be slow. Everything here stays in your browser, so testing a risky pattern never touches a server.

🎉 New here? Use code WELCOME10 for 10% off any plan at checkout
Regex Tester — Free Online Regular Expression Tester · PlayCISO