Regex Tester

Regular expressions (regex) are powerful patterns used to search, match, and manipulate text. Type your pattern and test string below — matches are highlighted in real time as you type. Supports all standard JavaScript regex flags: g (global), i (case-insensitive), m (multiline), and s (dotAll). Capture groups are displayed individually below the output.

/
Match Highlights
Matches will be highlighted here…
Regex Quick Reference
.Any character except newline
\dDigit [0-9]
\wWord character [A-Za-z0-9_]
\sWhitespace (space, tab, newline)
\D \W \SNon-digit, non-word, non-whitespace
^ $Start / end of string (or line with m)
* + ?0+, 1+, 0 or 1 repetitions
{n} {n,m}Exactly n, or n to m repetitions
[abc]Character class — a, b, or c
[^abc]Negated class — not a, b, or c
(abc)Capture group
(?:abc)Non-capture group
a|bAlternation — a or b
\bWord boundary
(?=abc)Positive lookahead
(?!abc)Negative lookahead

What this tool does

The Regex Tester lets you write a regular expression pattern, apply flags, and see all matches highlighted in real time as you type — without writing code or opening a terminal. Matches are highlighted inline, and all captured groups are listed below. Everything runs in the browser using JavaScript's native RegExp engine.

How to use it

  • Enter your regex pattern in the Pattern field.
  • Set flags using the toggle buttons (g = global, i = case-insensitive, m = multiline, s = dotAll).
  • Paste your test string — matches highlight live as you type in either field.
  • Check the Matches & Groups section below for all match positions and captured groups.
  • Expand the Regex Quick Reference at the bottom of the tool panel for a cheat sheet.

Debugging a pattern that isn't matching

  • Break the pattern into smaller pieces and test each one independently, then combine.
  • Check your flags — a pattern that works case-insensitively may fail without the i flag.
  • Watch for literal dot (\. not .) and escaped backslash (\\ not \).
  • Add m if your pattern uses ^ or $ and you're matching against multi-line text.

Frequently Asked Questions

What do the regex flags g, i, m, and s do?

g (global) — finds all matches, not just the first. i (case-insensitive) — matches regardless of case. m (multiline) — makes ^ and $ match the start/end of each line rather than the whole string. s (dotAll) — makes . match newlines too. Combine flags freely: gi matches all occurrences case-insensitively.

What is a lookahead and when would I use it?

A lookahead ((?=...)) asserts that what follows the current position matches a given pattern, without consuming characters. For example, \w+(?=\d) matches a word only if followed by a digit, but doesn't include the digit in the match. Negative lookahead ((?!...)) asserts the pattern does not follow. Lookaheads are useful for context-sensitive matching without capturing the context.

Why is my regex slow or causing the page to hang?

Some regex patterns exhibit catastrophic backtracking — the engine tries exponentially many paths before giving up, causing extreme slowness. This usually happens with nested quantifiers like (a+)+. Avoid redundant grouping and overlapping quantifiers. If you suspect this, simplify the pattern or use atomic groups where supported. This tester runs the regex on the live input, so a pathological pattern against a large test string can make the browser temporarily unresponsive.

Want the full explanation? Read the guide: Writing Regex That Doesn't Make You Hate Yourself →