Toolman

Regex Tester

Type a pattern and some test text. Matches highlight as you type, and every capture group is broken out below.

/ /

Matches

#MatchIndexGroups

Quick reference

PatternMatches
.Any character except newline (any character with the s flag)
\d \w \sDigit, word character ([A-Za-z0-9_]), whitespace
\D \W \SThe negation of each of the above
[abc] [^abc]Any one of a, b, c — or anything except them
[a-z]A character range
^ $Start and end of the string (or of each line with the m flag)
\bA word boundary
* + ?Zero or more, one or more, zero or one
{2} {2,} {2,5}Exactly 2, at least 2, between 2 and 5
*? +?Lazy versions — match as few characters as possible
(abc)Capture group
(?:abc)Group without capturing
(?<name>abc)Named capture group
a|bEither a or b
(?=abc) (?!abc)Lookahead: followed by / not followed by
(?<=abc) (?<!abc)Lookbehind: preceded by / not preceded by

Flags

gGlobal — find every match, not just the first
iCase-insensitive
mMultiline — ^ and $ match at line breaks
sDot-all — . also matches newlines
uUnicode — enables \p{...} property escapes and correct surrogate handling
ySticky — match only at lastIndex

Greedy vs lazy

Against <a><b>, the pattern <.*> matches the whole string because * is greedy — it takes as much as it can and then backtracks. <.*?> matches just <a>. Getting this wrong is the single most common regex bug.

Catastrophic backtracking

Patterns with nested quantifiers such as (a+)+$ can take exponential time on input that almost matches. On a server this is a denial-of-service vector known as ReDoS. Avoid nesting quantifiers, anchor patterns where possible, and prefer possessive or atomic constructs in engines that support them.

Where not to use regex

HTML, JSON, CSV and email addresses all have grammars that regular expressions cannot fully describe. Use a real parser for those. The official email regex from RFC 5322 is over 6,000 characters long — in practice, check for an @ with something either side, then send a confirmation message.

Frequently asked questions

Which regex flavour does this use?

JavaScript (ECMAScript), because it runs in your browser. Most syntax is shared with PCRE, Python and Go, but there are differences — JavaScript has no atomic groups or recursion, and its lookbehind support is newer than most.

Is my test data sent anywhere?

No. Matching happens with the browser’s own regex engine, so log excerpts and production data stay on your machine.

Why does my pattern hang the page?

Almost certainly catastrophic backtracking from nested quantifiers such as (\w+)+. Simplify the pattern or add anchors; the same pattern would hang your server too.

How do I match across multiple lines?

Add the s flag so . matches newlines, or the m flag so ^ and $ anchor to each line rather than the whole string. They solve different problems and can be combined.

What is the difference between $1 and $&lt;name&gt; in a replacement?

$1 refers to the first capture group by position; $<name> refers to a named group defined with (?<name>...). Named groups survive reordering of the pattern, which makes them far easier to maintain.

Related tools