Skip to content
cliplimeClipLime

Test regular expressions live

Highlighted matches, capture groups and a replace preview, with a guard against patterns that freeze the tab.

Runs in your browser, your text never leaves this page

Pattern

Flags

Test text

96 characters, 2 lines

Highlighted matches

Invoice sent on 2024-05-12, paid on 2024-06-03. Next review: 2025-01-15. Not a date: 12-05-2024.

Matches and groups

Testing…

Replace preview

Shows what the text becomes. Nothing is changed in your text box.

Result

Cheat sheet

This tool uses the JavaScript flavour of regular expressions, the same engine your browser runs.

Characters

.
Any character except a line break
\d \w \s
Digit, word character, whitespace
\D \W \S
The opposite of each
[abc] [a-z]
One of these characters, or a range
[^abc]
Anything except these
\p{L}
A Unicode letter (needs the u or v flag)
\n \t \\
Line break, tab, a backslash

Anchors and boundaries

^ $
Start and end of the text (or of each line with m)
\b \B
A word boundary, and where there is none

Quantifiers

* + ?
Zero or more, one or more, zero or one
{3} {3,} {3,5}
Exactly 3, at least 3, between 3 and 5
*? +? ??
The same, but as few as possible (lazy)

Groups and choices

(abc)
Capture group, numbered from 1
(?<name>abc)
Named capture group
(?:abc)
Group without capturing
a|b
Either a or b
\1 \k<name>
Match the same text again

Lookaround

(?=abc) (?!abc)
Followed by, or not followed by
(?<=abc) (?<!abc)
Preceded by, or not preceded by

In the replacement

$1 $2
The text of group 1, group 2
$<name>
The text of a named group
$& $$
The whole match, a dollar sign
$` $'
The text before and after the match

At a glance

Engine
JavaScript (ECMAScript) regular expressions, the same engine your browser uses, so a pattern that works here works in your JavaScript.
Flags
d, g, i, m, s, u, v and y, as toggles with a one line explanation each.
Output
Matches highlighted in your text, and a list with each match's position and every numbered or named capture group.
Replace
Preview $1, $<name>, $& and $$ replacements on the whole text before you use them in code.
Safety
Patterns run in a separate worker with a 2 second limit. Runaway backtracking is stopped and explained instead of freezing the tab.
Limits
The first 2,000 matches are collected, and highlighting works for text up to 100,000 characters.
Privacy
Your pattern and text stay on this page.

How to do it

  1. 1

    Type a pattern and pick flags

    Write the pattern between the slashes and switch flags on or off underneath. An error message appears if the pattern is not valid.

  2. 2

    Paste the text to test

    Matches are highlighted as you type, in alternating colours so neighbouring matches are easy to tell apart.

  3. 3

    Read the groups

    Each match lists its position and the text of every capture group, including named groups and groups that did not take part.

  4. 4

    Try a replacement

    Turn on Preview a replacement, write a template like $<day>/$<month>/$<year>, and see the rewritten text. The cheat sheet at the bottom covers the syntax.

What this tester runs

The pattern is compiled with new RegExp(pattern, flags) in your own browser, so the behaviour is exactly what your JavaScript or TypeScript code will see in that browser. Lookbehind, named groups and Unicode property escapes work where your browser supports them. The v flag is newer and needs a recent Chrome, Firefox or Safari, and it cannot be combined with u.

The flags change how a pattern behaves:

  • g finds every match. Without it only the first match is returned.
  • i ignores case. m makes ^ and $ match at each line. s lets the dot match line breaks.
  • u and v treat the text as Unicode code points, which matters for emoji and for \p{L}. Without them an emoji counts as two characters.
  • y matches only at the exact position where the search starts. d records where each group matched, which this page uses for the group positions.

If you are coming from another language, expect differences. JavaScript has no atomic groups or possessive quantifiers, no \A or \Z, and no inline flag at the start of a pattern such as (?i). Named groups are written (?<name>...), not (?P<name>...). Test the pattern in the engine you will actually use.

Catastrophic backtracking, and why the test runs in a worker

A regular expression engine tries alternatives and backs up when one fails. With a pattern like (a+)+$ on a long run of the letter a followed by a b, the number of ways to split the a's doubles with every extra letter. A few dozen characters can keep the engine busy for minutes. When this happens on a server it is called ReDoS, and it can take a service down.

JavaScript cannot interrupt a regex that is already running, so this page runs each test in a separate worker and stops that worker after 2 seconds. You get an explanation and a working page instead of a frozen tab. The worker is replaced on the next keystroke.

To make a slow pattern safe in your own code: avoid a repeat inside a repeat over the same characters, make alternatives not overlap, anchor the pattern, and limit the length of the text you test it against.

Capture groups and replacements

Parentheses capture part of a match. (\d{4})-(\d{2})-(\d{2}) captures the year, month and day of a date as groups 1, 2 and 3. Give a group a name with (?<year>\d{4}) to read it by name instead of by number.

In a replacement template $1 is the text of group 1, $<year> is the text of a named group, $& is the whole match and $$ is a literal dollar sign. The example loaded on this page turns 2024-05-12 into 12/05/2024. Code that needs to compute the replacement can pass a function to replace, which this preview does not cover.

A group that is inside an alternative that did not match, such as the first group in (a)|(b) when the text is b, is reported as undefined. This page labels it did not match.

Common mistakes

  • Forgetting to escape. A literal dot, bracket or plus sign needs a backslash: \. matches a full stop, while . matches almost anything.
  • Greedy repeats. <.+> swallows everything from the first < to the last >. Use <.+?> for the shortest match, or <[^>]+>.
  • Expecting \w to match accented letters. It only covers A to Z, a to z, digits and the underscore. Use \p{L} with the u flag for letters in any language.
  • No g flag. If only one match shows up, the g flag is off.

Questions people ask

Which regex flavour does this tester use?

JavaScript's. It runs the regular expression engine built into your browser, so it follows the ECMAScript rules. Patterns written for PCRE, Python, Java or .NET may need changes, especially for lookbehind, atomic groups and inline flags.

What does the g flag do?

The global flag makes the search continue after the first match so that every match in the text is found. Without it a regex stops at the first match, and the page tells you when that is why you only see one.

What is catastrophic backtracking?

It is when a pattern with nested or overlapping repeats can match the same text in an enormous number of ways, so a failing match takes exponential time. This tool stops such a pattern after 2 seconds and says so.

Why did my pattern work here but fail in my code?

Common reasons are a different flag set, a string literal that needs its backslashes doubled, or code running in an older browser or Node version without a feature you used, such as lookbehind or the v flag.

How do I match a literal dot, bracket or dollar sign?

Put a backslash in front of it: \., \[, \$. Inside a character class most symbols are literal already, so [.] matches a full stop. In a replacement template, write $$ for a literal dollar sign.

Is my text sent anywhere?

No. The pattern and the text are compiled and tested in a worker inside your browser, and nothing is sent to a server.