Regex Tester

Write a JavaScript regular expression, see every match marked in your text as you type, inspect its groups and preview a replacement.

Pattern
Pattern: //g
Test text
Matches
Replace preview
Cheat sheet
TokenMeaning
.Any character except a line break (any at all with the s flag)
\d \w \sDigit, word character (letter, digit, underscore), whitespace
\D \W \SThe opposite of each of the above
[abc] [^abc] [a-z]One of, none of, a range
^ $Start and end of the text (of each line with the m flag)
\bWord boundary
* + ?Zero or more, one or more, optional
{3} {2,5} {2,}Exactly 3, between 2 and 5, at least 2
*? +?Lazy: as few as possible
(abc)Numbered group, used as $1 in a replacement
(?<year>\d{4})Named group, used as $<year>
(?:abc)Group without capturing
a|bEither a or b
(?=x) (?!x)Followed by x, not followed by x
(?<=x) (?<!x)Preceded by x, not preceded by x
$& $$In a replacement: the whole match, a literal dollar sign

What a regex tester is for

A regular expression is a tiny program that describes a shape of text: "three digits, a dash, four digits", "a word that starts with a capital letter", "everything between two quote marks". They are compact and powerful, and they are also easy to get slightly wrong. A pattern that looks right can miss the last line of a file, swallow far more than you meant because a .* was greedy, or match nothing at all because of one unescaped dot. This page lets you try a pattern against real sample text and see at once what it catches, before you put it into code, a spreadsheet formula, a log filter or a form validation rule.

How to use it

  1. Type the pattern without the surrounding slashes. If you paste a full literal such as /\d+/gi, the slashes are removed and the matching flag boxes are ticked for you.
  2. Tick the flags you need. g finds every match instead of only the first, i ignores case, m makes ^ and $ work per line, s lets the dot cross line breaks, u turns on full Unicode handling, and y only matches at the exact position where the previous match ended.
  3. Paste your test text. Matches are marked in the right-hand pane and listed in the table with their start and end positions and every captured group, numbered and named.
  4. Optionally fill in Replace with to see the text after a find and replace, then copy the result.

How it works

This tester uses the regular expression engine built into your browser, the same one that runs String.prototype.match and replace in JavaScript and Node.js, so what you see here is exactly what your JavaScript code will do. Other languages use similar syntax, but details differ: PHP and Python support some constructs JavaScript lacks, such as possessive quantifiers, and JavaScript has its own named group syntax for replacements. Test in the dialect you will run.

Some patterns can take an extremely long time on certain inputs. A classic example is (a+)+$ against a long run of the letter a followed by one other character: the engine tries an exponential number of ways to split the run before giving up. This is called catastrophic backtracking, and it has taken down real websites. To keep this page responsive, every test runs in a separate background worker with a 500 millisecond budget. If the pattern has not finished by then, the worker is stopped and you see a warning instead of a frozen tab. That warning is a useful signal in itself: a pattern that is slow here can be slow in production too. The match list stops at 1000 entries so a pattern that matches every character cannot flood the page.

A worked example

Load the sample. The pattern (?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4}) with the g flag finds three dates written day first, such as 05-03-2026. Each row in the table shows the three named groups. The replacement $<year>-$<month>-$<day> rewrites every date into the sortable year first form, 2026-03-05, which is how you would clean up a column of dates before importing it into a database.

Limits and privacy

Empty matches, such as those from \b or a pattern that can match nothing, are counted in the list but have nothing to mark in the text. The engine is whatever your browser ships, so very new syntax may not work in an older browser. Your pattern and text are processed only inside this browser tab. Ur Next Door does not receive, store or log any of it, so you can safely test patterns against private logs, customer exports or source code.

Frequently Asked Questions

Which regex flavour does this tester use?
It uses the JavaScript engine built into your browser, so results match what String.match, matchAll and replace do in JavaScript and Node.js. PHP, Python and Java use similar syntax but differ in some features, so test in the dialect you will run.
Why does it say the pattern took too long?
Some patterns, such as (a+)+$, can backtrack for an extremely long time on certain text. Each test runs in a background worker with a 500 millisecond budget and is stopped if it runs over, so the page never freezes. Rewrite nested repeats to make the pattern safe.
How do I use groups in the replacement?
Use $1, $2 and so on for numbered groups, $<name> for a named group written as (?<name>...), $& for the whole match and $$ for a literal dollar sign. The preview updates as you type.
Is there a limit on matches?
The list shows up to 1000 matches. If there are more, the tool says so. The replace preview still applies to the whole text.
Is my text sent to a server?
No. The pattern and the test text are processed only in your browser tab. Ur Next Door never receives them, so it is safe for private logs and data.