RevealTheme logo

Regex Tester

Test JavaScript regular expressions against any input. See matches, groups, and replacements live.

0 match(es)

What are regular expressions and how do you read them?

Regular expressions (regex) are a tiny domain-specific language for matching patterns in text. Every modern programming language has a regex engine; this tool uses JavaScript's native RegExp, which follows the ECMAScript 2018+ specification and supports modern features like lookbehind assertions, named capture groups, Unicode property escapes, and the dotAll flag. The basic building blocks: literal characters match themselves (regex 'cat' matches the word cat); character classes match any one of a set ('[a-z]' matches lowercase letters); quantifiers control repetition (* zero or more, + one or more, ? zero or one, {3,5} between 3 and 5); anchors match positions (^ start of string, $ end, \b word boundary); groups capture submatches ((cat|dog) matches either, capturing which); alternation provides choice. Regex shines for parsing structured-but-not-grammatical text (logs, emails, phone numbers, simple HTML attributes) and falls apart for genuinely recursive structures (full HTML, nested JSON). For those, use a parser. This tester lets you iterate on a pattern with instant feedback — change the regex and the matches recompute on every keystroke.

Common use cases

  • Validate user input format (emails, phone numbers, postal codes) before sending to your server.

  • Extract structured data from log files (timestamps, IPs, status codes, request paths).

  • Find-and-replace across hundreds of files using your editor's regex search.

  • Write URL rewrite rules for Nginx, Apache .htaccess, or Vercel rewrites.

  • Parse simple CSV-like formats where a real parser is overkill.

  • Build form validation patterns for HTML <input pattern="..."> attributes.

Frequently asked questions

What flags are supported?
g (global — find all matches, not just the first), i (case-insensitive), m (multiline — ^ and $ match line breaks), s (dotAll — . matches newlines), u (unicode — proper handling of multi-byte characters), y (sticky — match at lastIndex only). Combine flags by concatenating: 'gim' enables global + case-insensitive + multiline.
How do I match across multiple lines?
Two different needs: 'm' makes ^ and $ match line breaks (treat each line as a separate string for anchors). 's' makes . match newlines (otherwise . matches everything except newlines). Use both together if you need to match patterns spanning lines.
What's the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, {n,m}) match as much as possible. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible. The classic example: regex '<.*>' on '<a><b>' matches the whole '<a><b>'; '<.*?>' matches just '<a>'.
When should I NOT use regex?
When the structure is genuinely recursive (HTML, JSON, balanced parentheses). When you need to handle every edge case correctly (parsing dates with timezones, names with apostrophes). When the input grammar is well-defined and a parser library exists. Famous Stack Overflow answer: regex is great for finding patterns, terrible for parsing languages.
What are named capture groups?
Instead of (\d{4})-(\d{2})-(\d{2}) returning numbered groups, use (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) and access matches as match.groups.year. Much more maintainable in real code.
Why is my regex slow on certain inputs?
Catastrophic backtracking. Nested quantifiers like (a+)+ can take exponential time on adversarial input. Avoid nested quantifiers and overlapping alternations. JavaScript's engine doesn't have a timeout, so a bad regex can hang a request. For production, use the safe-regex npm package to detect risky patterns.
Does this match what my server-side regex engine does?
Mostly — the major regex flavors (PCRE, Python re, Ruby regex, Java) are similar but have subtle differences. Lookbehind syntax, character class behavior, and Unicode handling vary. For production parity, test in the target language too.

Related tools