Regex Tester

Test regular expressions against sample text with live match and group highlighting. Supports all JavaScript flags — fully private.

Write, test, and debug JavaScript regular expressions with live match listings, capture-group readouts, and an instant replacement preview right in your browser. Type your pattern, choose your flags (g, i, m, s, u, y), and watch every match and captured group update on every keystroke. Everything runs locally — no sign-up, no server delay, and private log files stay on your device.

How to use Regex Tester

  1. Enter your regular expression into the Pattern field (without outer slashes) and set any flags you need (g, i, m, s, u, y).
  2. Paste the sample text, log lines, or HTML you want to test into the Sample text box.
  3. Inspect the live match list to verify exact match counts, character positions (@ index), and captured groups ($1, $2…).
  4. Optionally enter a replacement template (using $1 or $&) in the Replace all with field to preview the transformed text.

Who it is for

Developers, QA engineers, and data cleaners building validation rules or extraction scripts: verifying email, phone, or URL patterns, parsing server log lines, prototyping search-and-replace patterns with $1 and $& backreferences, and testing lookaheads, character classes, and capture groups on edge cases.

How it works

  • Patterns are compiled with your browser’s native ECMAScript RegExp engine, so what matches here matches identically in Node.js, TypeScript, and modern browsers.
  • The tool scans your sample text globally so every match appears with its exact character index and numbered capture groups ($1, $2, …), up to the first 100 matches for instant rendering.
  • Typing into the Replace all with box runs String.prototype.replace live with full support for $1, $2, and $& substitution tokens, while invalid patterns report the engine’s exact syntax error.

What it cannot do

  • It uses the JavaScript (ECMAScript) regex flavour. Features exclusive to PCRE, Python, or .NET — such as atomic groups (?>...), possessive quantifiers ++, or recursive patterns — are not supported by JavaScript’s engine.
  • Catastrophic backtracking patterns (like (a+)+b against a long string of a’s) can momentarily freeze the browser tab because JavaScript evaluates regular expressions on the main thread.
  • Match listings cap display at the first 100 matches to keep the page fast; for bulk text editing, use Find and Replace.

Sample input & output

You give

Pattern: \b([A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+\.[A-Za-z]{2,})\b | Flags: gi | Sample: Contact support@pdftura.com

Regex Tester returns

1 match at index 8–27 ("support@pdftura.com") | Group 1: "support" | Group 2: "pdftura.com"

Frequently asked questions

Which regex flavour does this tester use?

It uses your browser’s native JavaScript (ECMAScript) RegExp engine, including modern features such as lookbehind (?<=...), named groups (?<name>...), dotAll (s), and Unicode property escapes when the u flag is set.

Why are all matches listed even if I remove the g flag?

The match lister appends the g (global) flag internally so every match in your sample text is shown instead of stopping at the first hit. If you see only one match, your pattern genuinely matches once.

Why do ^ and $ match only the start and end of the whole text?

Add the m (multiline) flag in the Flags box so ^ and $ anchor to the beginning and end of each individual line.

Are my log files or test strings uploaded?

No. All regex compilation, matching, and replacement previews run locally inside your browser tab.

What do each of the JavaScript RegExp flags (g, i, m, s, u) change?

g (global) finds all matches rather than stopping after the first; i ignores case; m (multiline) makes ^ and $ match the start and end of each line rather than only the whole string; s (dotAll) lets . match newline characters; and u (unicode) enables full UTF-32 code-point matching and \p{...} Unicode property escapes.

Are lookaheads, lookbehinds, and named capture groups (?<name>...) supported?

Yes. Because Regex Tester executes directly on your browser's modern ECMAScript V8/SpiderMonkey/JavaScriptCore engine, positive/negative lookaheads ((?=...), (?!...)), ES2018 lookbehinds ((?<=...), (?<!...)), and named capture groups ((?<year>\d{4})) all work identically to modern Node.js and browser code.

Why does my regex work here in JavaScript but behave differently in Python, PHP PCRE, or Go RE2?

Regex engines differ in subtle features: Go's RE2 and Rust's regex crate disallow backreferences (\1) and arbitrary lookaround to guarantee linear O(n) execution time, whereas PHP PCRE2 supports atomic groups ((?>...)) and possessive quantifiers (a++) not present in standard JavaScript.

How do I avoid ReDoS (Regular Expression Denial of Service) in production validation?

Never nest repeating quantifiers with overlapping character sets — such as (\w+)* or ([a-z]+)+$ — which trigger exponential O(2ⁿ) backtracking in JavaScript's NFA engine when a trailing character fails to match, freezing the browser tab or Node.js event loop on inputs as short as 30 characters. Replace ambiguous wildcards with negated character classes ([^@\s]+ instead of .+) and enforce a strict maximum input length before running user-facing regexes.

How do Unicode property escapes (\p{L}, \p{Sc}) work with the u flag for multilingual text?

Without the u flag, JavaScript RegExp treats strings as 16-bit UTF-16 code units, splitting astral emoji into surrogate pairs and restricting \w to ASCII [A-Za-z0-9_]. Enabling the u flag switches the engine to full Unicode code-point mode and unlocks property escapes such as \p{L} (letters in any script including Bengali, Arabic, Devanagari, and CJK), \p{N} (numbers), and \p{Sc} (currency symbols) so international names and prices match cleanly without giant hex ranges.