Regex Tester

Test regular expressions with live, highlighted match groups.

Text
Pattern
//
Test String

How to use regular expressions

A regular expression (regex) is a sequence of characters that defines a search pattern. Regular expressions are used for input validation, text search and replace, log parsing, data extraction, and URL routing. Most programming languages include built-in regex support: RegExp in JavaScript, the re module in Python, preg_match() in PHP, and java.util.regex in Java.

A regex pattern is made up of literal characters, character classes ([a-z]), quantifiers (*, +, ?, {n,m}), anchors (^ for start, $ for end), groups (() for capturing, (?:) for non-capturing), and alternation (|). Common flags include g (global, find all matches), i (case-insensitive), and m (multiline, makes ^/$ match line boundaries).

This tester uses JavaScript's RegExp engine, which is ECMA-262 compliant. It supports lookaheads ((?=...)), lookbehinds ((?<=...)), named groups ((?<name>...)), and Unicode mode. It does not support PCRE-specific features like (*SKIP) or possessive quantifiers.

Common mistakes

  • Catastrophic backtracking — Nested quantifiers like (a+)+ can cause exponential backtracking on certain inputs, freezing the browser or server. Test with adversarial inputs before deploying to production.
  • Greedy vs lazy quantifiers — .* is greedy and matches as much as possible. .*? is lazy and matches as little as possible. Greedy quantifiers frequently cause unintended over-matching in HTML or JSON parsing.