DEVELOPER TOOL

Regex Tester

Test regular expressions with real-time match highlighting, capture group inspection, and detailed match information. Supports all JavaScript regex flags.

//g
Match Highlight

Matches will be highlighted here...

Mastering Regular Expressions

Pattern Matching: A Universal Skill

Regular expressions originated in the 1950s from mathematician Stephen Kleene's work on formal language theory. Ken Thompson implemented them in the QED text editor (1968), and they have been built into virtually every programming language since. Today, regex powers search-and-replace in IDEs, input validation in web forms, log parsing in monitoring systems, and data extraction in ETL pipelines. A single well-crafted regex can replace dozens of lines of procedural string-manipulation code.

The Building Blocks

\d digit [0-9] \w word char [a-zA-Z0-9_] \s whitespace

. any character ^ start of line $ end of line

* 0 or more + 1 or more ? 0 or 1 {n,m} n to m times

These fundamental atoms combine to form powerful patterns. For example, ^\d{4}-\d{2}-\d{2}$matches ISO date strings like “2025-03-23.” [A-Z]{2}\d{3}matches flight codes like “AA123.” Understanding these primitives lets you read and write regex for any text-processing task.

Capture Groups and Lookaround

Capture groups (pattern) extract matched substrings. In the pattern (\d{3})-(\d{4})matching “555-1234,” group 1 captures “555” and group 2 captures “1234.” Named groups (?<name>pattern) make code self-documenting. Lookahead (?=pattern) asserts what follows without consuming it. Lookbehind (?<=pattern) asserts what precedes. For example, (?<=\$)\d+ matches digits that follow a $ sign without including the $ in the match.

Catastrophic Backtracking

The most dangerous regex pitfall is catastrophic backtracking. Patterns like (a+)+$tested against “aaaaaaaaaaab” cause the engine to explore 2npossible paths — an input of just 25 “a”s followed by “b” can freeze your browser for minutes. This happens because the engine tries every possible way to divide the “a”s between the inner and outer groups before concluding there is no match. The fix: avoid nested quantifiers, use non-greedy matches when appropriate, and consider possessive quantifiers or atomic groups to prevent backtracking.

Frequently Asked Questions

What regex flavor does this tool use?

This tool uses JavaScript's built-in RegExp engine (ECMAScript specification). It supports lookahead, lookbehind (ES2018+), named capture groups, Unicode property escapes (\p{Script=Han}), and the “d” flag for match indices. Note that some features available in PCRE (Perl), .NET, or Python regex may not be supported — for example, recursive patterns and conditional groups are not available in JavaScript.

What do the flags (g, i, m, s) mean?

g (global): find all matches, not just the first. i (case-insensitive): A matches both “A” and “a.” m (multiline): ^ and $ match the start/end of each line, not just the entire string. s(dotAll): the . metacharacter matches newline characters (\n) in addition to all other characters. Without “s,” a dot will not cross line boundaries.

How can I make my regex more performant?

Anchor your patterns with ^ and $ when possible. Use character classes [abc] instead of alternation (a|b|c). Avoid .* when a more specific pattern exists. Use non-greedy quantifiers (*?, +?) when you need the shortest match. Most importantly, avoid nested quantifiers like (a*)*. If your regex runs against untrusted input, set a timeout or use a library with built-in backtracking limits.