Regex Tester

Test regular expressions instantly. Highlight matches, view match groups, and test with flags. Free online regex tester.

Regular expressions (regex) are patterns that describe how to match sequences of characters in text. They are one of the most powerful and widely used tools in programming — used for form validation (checking email addresses, phone numbers, postal codes), text search and replacement, log file parsing, URL routing, and data extraction from unstructured text.

A regex pattern is composed of literal characters and metacharacters. Literal characters match themselves exactly. Metacharacters have special meanings: . matches any character, * means zero or more of the preceding element, + means one or more, ? means zero or one, ^ anchors to the start of a string, $ anchors to the end, and brackets [ ] define character classes. Flags modify the behavior of the entire pattern.

This tester runs JavaScript's built-in RegExp engine. Enter your pattern without surrounding slashes, choose flags, provide a test string, and run the match. The tool highlights all matches in the test string and lists each match with its position and any capture groups. This interactive feedback makes it easy to build and debug complex patterns.

Common workflows include writing an email validation regex and testing it against valid and invalid addresses, building a log parsing pattern to extract timestamps and severity levels, or crafting a URL pattern for an HTTP router. All regex execution runs locally in your browser using JavaScript — no data is sent to any server.

//g

Cheat sheet for the metacharacters you will actually use

  • \d — any digit. \D — any non-digit.
  • \w — word character (letters, digits, underscore).\W — the inverse.
  • \s — whitespace. \S — non-whitespace.
  • . — any character except newline (unless the s flag is set).
  • * — zero or more. + — one or more. ? — zero or one.
  • {n,m} — between n and m repetitions.
  • (...) — capture group. (?:...) — non-capturing group. (?<name>...) — named group.
  • ^ / $ — start / end of string (or line with the m flag).

Greedy vs lazy quantifiers

By default, quantifiers are greedy: they match as much as they can..* against "abc"def matches abc"def, not just abc. Appending a ? makes the quantifier lazy: .*? matches as little as possible. This is how you extract a single quoted string without swallowing everything up to the last quote.

Engine differences

Not all regex engines are equal. JavaScript (used by this tool) is a backtracking engine with its own quirks — no possessive quantifiers, no atomic groups, limited look-behind support until recently. PCRE (Perl, PHP) is the most feature-rich. Go's regexp and re2 are linear-time by construction but deliberately drop backreferences. When porting a pattern between languages, test it against real inputs on the target engine rather than assuming a direct translation.

Related reading

A small mistake in a regex used on untrusted input can freeze a production server. Our article on regex performance and catastrophic backtracking walks through how to spot and fix these patterns.

Frequently Asked Questions