Regex Tester

Type a regular expression and some test text to see every match highlighted as you type, with positions, numbered and named groups, and a replacement preview using $1 or $<name>. Each part of the pattern is explained in plain language, all JavaScript flags can be switched on and off, and a library of tested patterns (email, URL, dates, IP addresses and more) gives you a starting point. Matching runs in a background worker with a time limit, so a runaway pattern can't freeze the page.

Pattern

What this pattern means

  • (?<year>\d{4})a capturing group named “year”
  • -the text “-”
  • (?<month>0[1-9]|1[0-2])a capturing group named “month”
  • -the text “-”
  • (?<day>0[1-9]|[12]\d|3[01])a capturing group named “day”

Test text

70 characters

Result

Matches highlighted
Released 2026-10-05, patched 2026-13-01 (invalid), retired 2027-01-31.
JavaScript
const re = /(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])/g;
const matches = [...text.matchAll(re)];

Runs entirely in your browser. Nothing you paste or open here is uploaded or stored.

How to use the regex tester

  1. Start from a common pattern in the list, or type your own between the slashes.
  2. Toggle flags with the buttons; g (global) is usually what you want for testing.
  3. Edit the test text. Matches are highlighted in alternating colours.
  4. Read “What this pattern means” to check that each token does what you intended.
  5. Turn on the replacement preview to try a replacement string.
  6. Copy the JavaScript snippet at the bottom into your code.

The match table lists each match with its start and end position and the value of every group. Named groups are shown by name.

How it works

The pattern is compiled with your browser’s own RegExp engine, so results match what your JavaScript code will do. Matching runs in a Web Worker, a separate thread. If it doesn’t answer within 1.5 seconds, the worker is terminated and restarted, and you’re told why. Zero-length matches (such as \b or x*) are handled by stepping forward one character (one code point with the u flag), so the search always finishes. Results stop at 1,000 matches.

Worked examples

Example 1: reformatting dates

The default pattern (?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>…) finds ISO dates and rejects month 13. With the replacement $<day>.$<month>.$<year>, 2026-10-05 becomes 05.10.2026, the format used in Germany.

Example 2: finding repeated words

Load Repeated word: \b(\w+)\s+\1\b with the i flag. It finds “is is” and “the the” in the sample, because \1 must repeat whatever group 1 matched.

Example 3: validating slugs line by line

Load URL slug with the m flag. ^ and $ then anchor each line, so my-blog-post and version-2-0 match while Another Post and trailing- don’t. Without m, the anchors apply to the whole text and nothing matches.

Writing better patterns

  • Anchor validation patterns with ^…$, or a partial match will pass.
  • Prefer specific classes ([^"]*) over .*, which is greedy and slow.
  • Use non-capturing groups (?:…) when you don’t need the value.
  • Escape special characters (. * + ? ( ) [ ] { } | \ ^ $) when you mean them literally.

Common mistakes

  • Forgetting g when you expect all matches.
  • Double escaping. In a JavaScript string, "\\d" is needed; in a regex literal, /\d/ is enough. The tester uses literal syntax.
  • Greedy matches across tags. <.*> matches from the first < to the last >; use <[^>]*>.
  • Parsing HTML or JSON with regex. Use a real parser for nested structures.

Frequently asked questions

Which regex flavour does this use?

JavaScript (ECMAScript) regular expressions, exactly as your browser runs them, including named groups, lookbehind, Unicode property escapes with the u flag, and the d flag for match indices. Patterns usually work the same in Java, Python and PCRE, but details differ (for example, Python writes named groups as (?P<name>…)).

What do the flags do?

g finds all matches instead of the first; i ignores case; m makes ^ and $ match at line breaks; s lets . match newlines; u enables full Unicode handling; y matches only at the current position; d records the start and end of each group.

Why did my pattern time out?

Some patterns, especially nested repetition like (a+)+ or (.*)*, can take exponential time on text that almost matches. This is called catastrophic backtracking. The tester stops after 1.5 seconds and warns you; rewrite the pattern so that each part can match in only one way.

Is the email pattern fully correct?

No regex validates every address the standards allow, and you shouldn't try. The library pattern accepts realistic addresses and rejects obvious typos. The only real check is sending a confirmation email.

How do I match a literal dot or bracket?

Escape it with a backslash, such as \. for a dot or \[ for a bracket. Inside a character class, most characters are literal, so [.] also matches a dot.

Sources