Regex tester

Highlight matches, preview replacements, save reusable rules and verify expressions with positive and negative tests.

  • Runs locally
  • Free

Use the tool

Your files are processed in your browser and are not uploaded to a server.

About this tool

Test regular expressions online: highlight matches, inspect capture groups, preview replacements and verify patterns with positive and negative test cases. Save useful rules to a local library.

Typical uses

  • Write and verify a phone or email validation pattern
  • Debug capture groups in a log-parsing rule
  • Preview the result of a bulk replacement

How to use

  1. Enter a JavaScript pattern and flags to inspect matches, captures and replacements. Add positive and negative cases in the test suite, choosing contains or full matching.

  2. Run and inspect passing and failing cases. Name and save reusable rules; explicitly opt in to saving replacement templates or test cases. Preview imports before merging.

Example

Test [A-Z]{2}\d{4} using AB1234 as a positive full-match case and AB123 as a negative case. Run the suite, then save the rule and explicitly choose whether to include those samples.

Good to know

Pattern: 1000 characters; main text: 50K; displayed matches: 200; replacement output: 200K. Suites: 30 cases, 5000 characters each and 50K total, run in a Worker with a 1.5-second suite timeout. The local rule library holds 30 rules / 256 KiB. Test inputs are not saved by default.

Uses JavaScript regex semantics, which differ from other languages. Full matching must cover the entire sample. Expressions are recreated per case, including g and y. Rules and optional samples stay local; inspect contents before exporting samples.

The six flags, and what u changes

The tool runs your pattern on the browser’s own JavaScript RegExp engine. These are the only six flags you can tick; the order you tick them in does not matter, the tool always writes them as gimsuy.

FlagLabelEffect
gGlobalFind every match; without it only the first match is found and replaced
iIgnore caseA and a are treated as the same letter
mMultiline anchors^ and $ also match at the start and end of each line
sDot matches newlines. also matches line breaks
uUnicodeWorks on whole Unicode code points and enables \p{…} property classes
yStickyEach match must start exactly where the previous one ended; nothing may be skipped

Every result in this table was produced by the tool’s matching engine. Positions are UTF-16 offsets and [start, end) excludes the end:

PatternTest textResult in this tool
/^.$/"😀"no match
/^.$/u"😀""😀" [0, 2)
/(?:)/g"😀"(empty match) [0, 0) · (empty match) [1, 1) · (empty match) [2, 2)
/(?:)/gu"😀"(empty match) [0, 0) · (empty match) [2, 2)
/\p{L}+/g"café p{L}""p{L}" [5, 9)
/\p{L}+/gu"café p{L}""café" [0, 4) · "p" [5, 6) · "L" [7, 8)
/\bcafé\b/gu"un café noir"no match
/(?<![\p{L}\p{N}_])café(?![\p{L}\p{N}_])/gu"un café noir""café" [3, 7)
/\d+/gu"123 ١٢٣ 123""123" [8, 11)
/^\w+$/gm"東京↵abc""abc" [3, 6)
  • An emoji takes two UTF-16 positions. Without u, . consumes only half of it, so ^.$ does not match “😀”, and an empty match lands in the middle of the emoji (position 1).
  • Without u, \p{L} is not a Unicode property at all: it is the letter p followed by a literal “{L}”, so it only matches the text “p{L}”. Always tick u when you use \p{…}.
  • \d, \w and \b stay ASCII-only even with u: full-width “123” and Arabic-Indic digits are not \d, Chinese characters are not \w, and there is no \b after the é of “café”. To match words in other scripts, use \p{L}, \p{N} and lookarounds as in the fixed row.
  • The ES2024 v flag and the d (indices) flag are not offered. The engine accepts only these six letters and answers anything else, or a repeated flag, with “Use each of g, i, m, s, u and y at most once.” An imported rule file that uses another flag is rejected as invalid.

Replacement templates, exactly

“Replace preview” builds its output with the string-template rules of JavaScript’s String.replace. Each row below was computed by the tool:

PatternTest textReplacement templateResultWhy
/(?<user>[\w.+-]+)@(?<domain>[\w.-]+\.[a-z]{2,})/gi"ada@example.com, help@doc80.com"$<user> [at] $<domain>"ada [at] example.com, help [at] doc80.com"Named groups are referenced as $<name>
/\d+/g"a12 b7"[$&]"a[12] b[7]"$& is the whole match
/\d+/g"12"$$$&"$12"$$ writes a single dollar sign
/\d+/"ab12cd"<$`|$'>"ab<ab|cd>cd"$` and $' are the text before and after the match
/(\d+)/g"a12"$10"a120"With only one group, $10 is read as $1 followed by the digit 0
/(?<y>\d{4})-(?<m>\d{2})/g"2026-11"$<zz>|$2"|11"An unknown group name becomes an empty string
/(\d{4})/g"2026"$<y>"$<y>"If the pattern has no named groups at all, $<y> stays as typed
/\s+/g"a b↵c"\n"a\nb\nc"A typed \n is two ordinary characters, not a line break; press Enter for a real one
/\d/"a1b2"#"a#b2"g is off, so only the first match is replaced
  • In the “Find matches” table, a capture group that did not take part in the match shows “unmatched”, which is different from a group that matched an empty string. In a replacement, both become empty.
  • A zero-length match is listed as “(empty match)”.

Patterns copied from Python or PCRE

The same pattern can mean something quite different in another engine. The left side shows syntax from Python’s re module (as its documentation describes it) or PCRE; the right side is what this tool’s JavaScript engine actually does with it:

PatternTest textMeaning in Python reResult in this tool
/a++/g"aaa"Possessive quantifier (Python 3.11+), no backtrackingsyntax error (Invalid expression)
/(?>a+)/g"aaa"Atomic group (Python 3.11+)syntax error (Invalid expression)
/(?P<y>\d{4})/g"2026"Python’s named-group syntaxsyntax error (Invalid expression)
/(?i)abc/g"ABC"At the start: case-insensitive for the whole patternsyntax error (Invalid expression)
/\Aabc/g"abc Aabc"\A matches only at the start of the string"Aabc" [4, 8)
/\Aabc/gu"abc Aabc"Same as abovesyntax error (Invalid expression)
/abc\Z/g"abc abcZ"\Z matches only at the end of the string"abcZ" [4, 8)
/(?<=USD|¥)\d+/g"¥1200 USD30 €5"Python requires fixed-width lookbehind; USD|¥ has two widths and is rejected"1200" [1, 5) · "30" [9, 11)
  • Errors are the easy case. The dangerous one is a pattern that still runs but means something else: without u, \A and \Z are just the letters A and Z. With u ticked, such unknown escapes become syntax errors, which makes the mistake visible.
  • JavaScript equivalents: (?<y>…) for named groups, the i flag instead of (?i), and ^ / $ without m for the start and end of the text.
  • JavaScript accepts variable-width lookbehind such as (?<=USD|¥)\d+, so that pattern works here as written.
  • In Python, \d matches any Unicode decimal digit by default; here \d matches 0–9 only (see the first section).
  • On a syntax error the status line shows “Invalid expression: ” followed by the browser’s own explanation, whose wording depends on the browser.

Timeout, limits and how matches are counted

Patterns run in a separate Worker thread, so the page never freezes. If no answer arrives within 1.5 seconds of sending the request, the tool terminates that worker and shows “Stopped after 1.5 seconds. Shorten the text or simplify the expression.”

  • The classic catastrophic pattern is ^(a+)+$. Against “aaaa…a!”, where the last character fails, the nested quantifier tries every way of splitting the a’s; each extra a roughly doubles the work, so a few dozen characters reach the limit. ^a+$ means the same thing and finishes instantly.
  • Patterns are limited to 1,000 characters, test text to 50,000 characters (UTF-16 units, so an emoji counts as 2) and replacement templates to 10,000.
  • “Find matches” lists at most 200 matches and stops when it finds match 201, so /a/g on 300 a’s shows the count “≥ 201”, meaning “at least”. “Replace preview” processes every match and reports 300 for the same text.
  • Match and capture text kept for display is capped at 120,000 characters in total; longer values are shortened but their offsets still describe the full match. A replacement longer than 200,000 characters is shown only from the start, and its download name contains “partial”.
  • In “Test suite”, a full-match case actually runs ^(?:pattern)$(?![\s\S]). So a|ab passes on “ab” (the outer group lets it backtrack to ab), while \d+ with m fails on “123\n”, because $(?![\s\S]) demands the real end of the text. A suite holds up to 30 cases of 5,000 characters each.

Sources

Frequently asked questions

Which regex flavor is used?

JavaScript (ECMAScript) syntax and flags.

Can a heavy regex freeze the page?

No. Tests run in a background worker and stop after 1.5 seconds.

Is my test text saved?

Test inputs are not saved by default; replacement templates and test cases are saved only if you opt in.