Skip to content

Regex tester

Live matches, groups and replace for JavaScript regular expressions.

Updated

Mode
Flags

3 matches

Invoices are due on 2026-10-31 and 2026-11-30.
The contract started 2024-01-15.
#MatchPositionGroups
12026-10-3120–30
  • 1 year: 2026
  • 2 month: 10
  • 3 day: 31
22026-11-3035–45
  • 1 year: 2026
  • 2 month: 11
  • 3 day: 30
32024-01-1568–78
  • 1 year: 2024
  • 2 month: 01
  • 3 day: 15

How to test a regular expression

  1. Type your pattern without the surrounding slashes, and choose its flags.
  2. Paste the text to test against. Matches are highlighted as you type.
  3. Read each match's position and groups in the table under the text.
  4. Switch to Replace to try a replacement with $1 or $<name>, then copy the result.

Patterns run in JavaScript's own engine, so a pattern that works here works the same inString.prototype.match, replace and RegExp.prototype.exec. Test text can be up to 200,000 characters, and up to 1,000 matches are shown.

Flags

FlagNameEffect
gglobalFind every match, not just the first
iignore casea matches A
mmultiline^ and $ match at the start and end of each line
sdotAll. also matches line breaks
uunicodeTreats emoji and other astral characters as one character and enables \p{…}
ystickyEach match must start exactly where the last one ended

Quick reference

SyntaxMatches
\d, \w, \sA digit, a word character (letter, digit or _), whitespace
[abc], [^abc]One of a, b or c; anything except them
a*, a+, a?, a{2,4}Zero or more, one or more, optional, two to four
a+?Lazy: as few as possible
^, $, \bStart, end, a word boundary
(abc), (?<name>abc), (?:abc)Numbered group, named group, group without capturing
a(?=b), a(?!b)a followed by b; a not followed by b
(?<=b)a, (?<!b)aa after b; a not after b
\p{L} (with u)Any letter, in any alphabet

Slow patterns

JavaScript's engine backtracks: when part of a pattern fails, it goes back and tries other ways to match. Nested quantifiers such as (a+)+$ or (\w+\s?)*$ can make the number of attempts explode on text that almost matches, which is known as catastrophic backtracking, or ReDoS when it's exploited. The tester stops any run that takes more than one second and tells you. Make each part of the pattern match less, for example [^"]* instead of .*, and avoid quantifiers inside quantified groups.

Common uses

  • Building a validation pattern. Paste sample inputs, good and bad, one per line, and refine a pattern with the m flag until it matches exactly the lines it should.
  • Pulling data out of text. Write a pattern with named groups to extract dates, IDs or prices from a log or an email, and read each group's value and position in the match list.
  • Reformatting with find and replace. Rearrange text with groups, such as turning 2026-10-31 into 31/10/2026, check the result in Replace mode, and copy it out.

Questions

Which regex flavour does this use?

JavaScript (ECMAScript), exactly as your browser runs it, including named groups, lookbehind and \p{…} Unicode properties with the u flag. Patterns from PCRE, Python or .NET mostly work, but features like possessive quantifiers, atomic groups and inline (?i) modifiers may not.

Why does my pattern only find one match?

Without the g (global) flag, JavaScript stops at the first match. Turn on g to find them all. The y (sticky) flag also changes things: each match must start exactly where the previous one ended.

What does “matching took too long” mean?

Some patterns, usually nested quantifiers like (a+)+ or (.*)*, can try an enormous number of ways to match before failing. The tester stops any run after one second instead of freezing the page. Make the pattern more specific, for example by replacing .* with [^,]*.

How do I use groups in a replacement?

$1, $2 and so on insert numbered groups, $<name> inserts a named group, $& the whole match, and $$ a literal dollar sign. Switch to Replace mode to see the result as you type.