Skip to content
Sealpaste

Delete all recent work?

This removes the 0 items saved in this browser. Your settings stay.

Stop saving recent work?

New work won't be saved in this browser. The 0 items already saved can stay or go.

Regex Tester

/
/g
Text

Type a pattern and paste text, or

Ready
Runs in your browser. Nothing you paste is uploaded unless you share it.

Test a JavaScript regex: every match marked, each group in a table, Replace with $1, and the pattern explained

Type a JavaScript regular expression and paste your text: every match is marked as you type, each group gets its own column, and every part of the pattern is explained in plain English. Replace shows the new text with $1 and $<name>.

How to use it

  1. Type a pattern, or pick a common one, and open Flags for the ones it needs (g finds every match).
  2. Paste the text to test, or open a file of up to 10 MB.
  3. Read the matches and their groups (click one to find it in the text), switch to Replace, Explanation, Tests, Code or Steps, and copy the matches as JSON, CSV or text.

Examples

Dates, with named groups

Input
/(?<year>\d{4})-(?<month>\d{2})/g
Shipped 2026-10-15, paid 2026-09-30.
Result
[
  {
    "match": "2026-10",
    "year": "2026",
    "month": "10"
  },
  {
    "match": "2026-09",
    "year": "2026",
    "month": "09"
  }
]

Copy gives each match with its groups by name, as JSON, JSON Lines, CSV or text.

Prices after a dollar sign (lookbehind)

Input
/(?<=\$)\d+(?:\.\d{2})?/g
Total $42.50, tax $3, code A12.
Result
[
  "42.50",
  "3"
]

(?<=\$) checks for the $ without making it part of the match; A12 has no $ before it.

Key = value lines, with the m flag

Input
/^(\w+)\s*=\s*(.*)$/gm
host = example.com
port=8080
# a comment
Result
[
  {
    "match": "host = example.com",
    "group 1": "host",
    "group 2": "example.com"
  },
  {
    "match": "port=8080",
    "group 1": "port",
    "group 2": "8080"
  }
]

With m, ^ and $ match at every line; without it, only at the start and end of the text.

Replace: a date as day/month/year

Input
/(\d{4})-(\d{2})-(\d{2})/g
Replace with: $3/$2/$1
Renewal due 2026-11-01, review 2027-01-15.
Result
Renewal due 01/11/2026, review 15/01/2027.

A group left open

Input
/(?<year>\d{4}/g
2026-10-15
Result
Not a valid pattern. Character 1: Unterminated group: a "(" without its ")"

The part that is wrong is marked in the pattern, and the explanation reads up to it.

JavaScript, PCRE2, Python, Go, Java, .NET and Rust

With Flavor on JavaScript, the matching is done by your browser’s own regular expression engine, the one your JavaScript or TypeScript code uses, so what you see is what new RegExp(pattern, flags) gives in your app.

Pick another flavor and the pattern is read by that engine’s rules, then rewritten into JavaScript that matches the same. The differences that change a match are carried over: Python’s and .NET’s \d and \w take digits and letters of every script, $ also matches before a final line break in PCRE2, Python, Java and .NET, the dot in Java stops at \r and \u0085 too, and possessive repeats (a++) and atomic groups ((?>…)) give nothing back. .NET numbers its named groups after the others, and the table does too.

What an engine refuses is refused here, at its place in the pattern: lookbehind in Go and Rust, a lookbehind of varying width in Python, (?P<name>…) in Java. What JavaScript can’t do at all, such as recursion, conditionals and \G, is named instead of run. POSIX is not offered: it picks the longest match, which no backtracking engine does.

A pattern that can’t be read is not run: the part that is wrong is marked in the pattern, and the status bar says where (the character, or the flags).

Sources: MDN: Regular expressions, PCRE2 pattern syntax, Python re, Go regexp/syntax, Java Pattern, .NET regular expressions, Rust regex syntax

The flags

Flags change how the whole pattern matches. In code they go after the closing slash (/a/gi) or as the second argument of new RegExp. Flags in this tester lists each one with what it does; Copy beside the pattern gives it as /…/flags.

FlagNameWhat it does
gglobalFinds every match, not just the first
iignore caseUpper and lower case match each other (a matches A)
mmultiline^ and $ match at the start and end of every line
sdotAllThe dot matches line breaks too
uunicodeReads the pattern as Unicode: \u{…}, \p{…}, and emoji as one character
vunicodeSetsUnicode, plus set operations in classes ([\p{L}--[a-z]]); not with u
ystickyMatches only exactly at lastIndex, not further on
dhasIndicesReports where each group matched (this tester shows that without it)

Sources: MDN: RegExp flags

Cheat sheet

The parts you use most. The Explanation view says the same for any pattern you type.

PatternMatches
\d \w \sA digit; a word character (A–Z, a–z, 0–9, _); whitespace
\D \W \SAnything but a digit, a word character, whitespace
.Any character except a line break (with s, line breaks too)
[abc] [^abc] [a-z]One of a, b, c; anything but them; a range
^ $The start and end of the text (with m, of each line)
\bA word boundary: between a word character and something else
* + ?Zero or more; one or more; zero or one, as many as possible
{3} {2,5} {2,}Exactly 3; 2 to 5; 2 or more
*? +? ??The same, as few as possible (lazy)
(…) (?<name>…)A group, captured by number; by name
(?:…)A group that is not captured
\1 \k<name>The same text as group 1 matched; as the named group
a|ba or b
(?=…) (?!…)Followed by, not followed by (not part of the match)
(?<=…) (?<!…)Preceded by, not preceded by

match, matchAll, exec, test and replace

The same pattern gives different results depending on the method and the g flag. The Matches table shows what matchAll gives: every match with its groups.

CallGives
text.match(/…/)The first match with its groups and index, or null
text.match(/…/g)Every matched string, without groups, or null
text.matchAll(/…/g)Every match with its groups; a TypeError without g
re.exec(text)One match with its groups; with g or y it starts at re.lastIndex and moves it on
re.test(text)true or false; with g or y it also moves lastIndex on
text.replace(/…/, x)The first match replaced; with g, every match
text.replaceAll(/…/g, x)Every match replaced; a TypeError without g

Sources: MDN: String.prototype.matchAll(), MDN: RegExp.prototype.exec()

Replacement patterns

In the Replace view, and in replace() and replaceAll(), these stand for parts of each match. A function instead of a string gets the match, then each group, and returns the new text: text.replace(re, (match, year) => …).

WriteFor
$1 … $99The text of that numbered group
$<name>The text of the named group
$&The whole match
$`The text before the match
$'The text after the match
$$A $ sign

Sources: MDN: Specifying a string as the replacement

When a pattern takes too long

Some patterns try an enormous number of ways to match before they give up: (a+)+$ on a line of a’s that ends in ! takes about twice as long with every a added. This is catastrophic backtracking, and on a server it is a denial-of-service risk (ReDoS).

Here the matching runs in a background thread and is stopped after 5 seconds, so the page keeps answering, and the result says why. The usual fix: a repeat inside a repeat ((a+)+, (\w+\s?)*) where one is enough, or alternatives that can match the same text ((a|a)*).

/(a+)+$/.test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!")  // stopped here; slow in your code

Sources: OWASP: Regular expression Denial of Service

Questions

Which regex flavor does it test?
JavaScript by default, with your browser’s own engine. The Flavor menu also reads patterns by the rules of PCRE2 (PHP), Python 3.11, Go, Java 21, .NET and Rust: their anchors, dot, \d, \w and \b, named groups, inline flags, possessive repeats and atomic groups, and their replacement syntax ($1, \1, \g<name>, ${name}).
Can I save a pattern to use again?
Yes: My patterns saves the pattern in the boxes, with its flags, flavor and replacement, under a name you choose (up to 50). They are kept in this browser, not the text; pick one to fill the boxes again, or delete it there. Delete all data in Settings clears them too.
Can I see how the engine finds a match, step by step?
Yes: Steps walks the start of your text (2,000 characters) the way JavaScript’s engine does, each part of the pattern tried at its place, what it matched, and each step back when a way fails, up to the first match. A pattern that backtracks too much stops at 20,000 steps, which is how catastrophic backtracking shows.
Can it write the regex as code for my language?
Yes: Code gives the pattern and the code that finds every match (or the first) and makes the replacement, in JavaScript, Python, PHP, Go, Java, C#, Rust or Ruby. The pattern is rewritten so it matches the same text there: JavaScript’s ASCII \d, \w and \b are kept, the dot and ^ $ stop where JavaScript stops, and a Unicode property the engine lacks is written out as ranges. A note says what still differs (.NET reads emoji as two halves), and what an engine can’t do, such as a backreference in Go or Rust, is named instead of written.
Why does it find only the first match?
Without the g flag a regex stops at its first match. Open Flags and turn on g to find them all; the page says so when g is off.
Why does test() return true, then false, on the same text?
With the g or y flag, test() and exec() start at the regex’s lastIndex and move it past each match. The second call starts after the first match, finds nothing more and sets lastIndex back to 0. Use a regex without g for test(), or set re.lastIndex = 0 before each call.
Does JavaScript support lookbehind?
Yes: (?<=…) and (?<!…) are part of JavaScript since ES2018 and work in current Chrome, Edge, Firefox and Safari (16.4 and later). In JavaScript they can be any length, which many other engines don’t allow.
How do I match across lines?
The dot doesn’t match line breaks by default. Turn on the s flag so it does, or use [\s\S] for any character. To make ^ and $ match at each line instead of the whole text, turn on m.
Greedy or lazy: what is the difference?
* and + take as much as they can, then give back only what the rest of the pattern needs: ".*" on "a" and "b" matches the whole "a" and "b". Add ? to take as little as possible: ".*?" matches "a" and "b" separately.
Which characters need a backslash?
These have a meaning in a pattern: \ ^ $ . | ? * + ( ) [ ] { }. Put a backslash before one to match it as itself (\. matches a dot). In /…/ also escape /; in a string passed to new RegExp, each backslash is written twice ("\\d").
Can a regex check an email address?
Only roughly. The common pattern finds things that look like an address, which is what most forms need; whether the address works is only known by sending mail to it. Browsers check <input type="email"> with a similar simple pattern.
How much text can it test?
Up to 10 MB, pasted or from a file. The first 10,000 matches are found and the first 500 listed in the table; Copy has every match found, as JSON, JSON Lines, CSV or text. A pattern that runs over 5 seconds is stopped.
Is my text uploaded?
No. Everything runs in your browser, so your text stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first. Logs can hold API keys and tokens, and the page warns you if it spots one.

Related tools