Regex Tester

Live match highlighting, capture groups and replace

//

Enter a pattern.


    

How to test a regular expression

  1. Type your pattern between the slashes. Flags can be typed or toggled with the checkboxes.
  2. Paste the text you want to search into Test string. Matches are highlighted live as you edit either box.
  3. The table lists every match with its position and each capture group, including named groups such as (?<year>\d{4}).
  4. Enter a replacement to preview a find-and-replace. Use $1 for the first group, $<name> for named groups and $& for the whole match.
  5. Not sure where to start? Insert a ready-made pattern for emails, URLs, IP addresses, dates or colours from Examples.

Which regex flavour is this?

The tester uses your browser's JavaScript (ECMAScript) regex engine, the same one used by Node.js, TypeScript and Deno. Most syntax is shared with Python, Java, PHP (PCRE) and .NET, including character classes, quantifiers, anchors, lookahead and lookbehind. Differences to know: JavaScript has no possessive quantifiers or atomic groups, uses (?<name>) for named groups, and needs the s flag for . to match newlines.

Protection against freezing

Some patterns, such as (a+)+$, take exponential time on certain inputs. This is called catastrophic backtracking and it is a real cause of outages (ReDoS). Matching runs in a background worker that is stopped after 1.5 seconds, so a bad pattern shows a warning instead of locking up the page. Your pattern and text stay in your browser.

Why does my regex match only once?

Without the g (global) flag JavaScript stops after the first match. Tick g to find all matches.

How do I match a literal dot or bracket?

Escape it with a backslash: \. matches a dot, \( a parenthesis and \[ a square bracket. Inside a character class most symbols are literal, so [.] also matches a dot.

What do ^ and $ match?

By default the start and end of the whole text. With the m (multiline) flag they match the start and end of each line.

Made by BufferMint. We also design and build software products for founders. See our services →

Your files and inputs never leave your device; we only count anonymous visits.