Regex Tester

Test regular expressions with live match highlighting, group capture and replace mode

/ /
Replace Mode
Result after replace:

Quick Reference

  • . — any character
  • \d — digit [0-9]
  • \w — word char [a-z0-9_]
  • \s — whitespace
  • ^ — start of string
  • $ — end of string
  • * — 0 or more
  • + — 1 or more
  • ? — 0 or 1
  • {n,m} — n to m times
  • (abc) — capture group
  • [abc] — character class
  • a|b — a or b

Common Patterns

  • Email address
  • URL
  • Date YYYY-MM-DD
  • IPv4 address
  • Hex color
  • Numbers
  • Capitalized words

Free Online Regex Tester

Test, debug and validate regular expressions in real time. Type your pattern and test string — matches highlight instantly. View every match with its position and captured groups. Use replace mode to test substitutions. Includes a cheat sheet and one-click common patterns.

Features

Live Highlighting

Matches are highlighted in real time as you type — both in the test string view and in the match list below.

Capture Groups

All capture groups (numbered and named) are extracted and shown for each match with their values.

Replace Mode

Test find-and-replace operations with backreferences ($1, $2) and see the full result after substitution.

All Flags Supported

Toggle g, i, m, s flags with checkboxes — no need to remember syntax. Each flag is explained by tooltip.

Common Patterns

One-click patterns for email, URL, date, IPv4, hex color and more — click any to load it instantly.

Built-in Cheat Sheet

Quick reference sidebar covering all essential regex tokens — always visible while you work.

Who Uses This Tool?

DevelopersWrite and test patterns for form validation, log parsing, data extraction and string manipulation.
Data AnalystsExtract specific fields from unstructured text, clean datasets and validate data formats in pipelines.
Security EngineersWrite patterns for WAF rules, log analysis and intrusion detection systems.
Students & LearnersLearn regex by experimenting with patterns and immediately seeing which parts of text they match.

Common Questions

What is a regular expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to find, match, validate or replace text. For example, \d+ matches one or more digits, [a-z]+ matches lowercase letters, and ^\w+@\w+\.\w+$ validates a simple email format.
What do the flags g, i, m, s do?
g (global) finds all matches instead of stopping at the first. i (case-insensitive) makes the pattern ignore upper/lower case. m (multiline) makes ^ and $ match the start and end of each line instead of the whole string. s (dotAll) makes the dot (.) also match newline characters.
What is a capture group and how do I use it in Replace?
A capture group is text enclosed in parentheses () in your pattern. It captures the matched text for that sub-pattern separately. In Replace mode, reference groups with $1, $2, etc. For example, pattern (\d{4})-(\d{2}) with replace $2/$1 would transform 2026-04 into 04/2026.
Does this use JavaScript regex?
Yes — this tester uses JavaScript's built-in RegExp engine. JavaScript regex is widely compatible but has some differences from PCRE (used by PHP, Python, Perl). Lookahead, lookbehind, named groups and Unicode are all supported in modern JavaScript engines.

Pro Tip

When writing a regex for validation (e.g. email, phone, postcode), always anchor it with ^ at the start and $ at the end. Without anchors, a pattern like \d+ would match any string containing a digit — including "abc123xyz". With anchors, ^\d+$ only matches strings that are entirely digits.

Did You Know?

1951
Regex Was Invented
Regular expressions were invented by mathematician Stephen Cole Kleene in 1951 as a notation for describing regular languages. They were first implemented in the UNIX text editor ed in 1969, and have been a fundamental tool in computing ever since.
O(n)
Regex Time Complexity
Most simple regex patterns match in O(n) time (linear). However, certain patterns with nested quantifiers like (a+)+ can cause catastrophic backtracking — exponential time O(2ⁿ) — bringing servers to their knees. This is called ReDoS (Regular Expression Denial of Service).
RFC 5322
True Email Regex Standard
The technically correct regex for RFC 5322 email validation is over 6,000 characters long. In practice, developers use simplified versions like /^[^\s@]+@[^\s@]+\.[^\s@]+$/ which covers 99.9% of real-world emails without the complexity.

Essential Regex Token Reference

TokenMeaningExampleMatches
.Any character (except newline)c.tcat, cut, c3t
\dDigit [0-9]\d{3}123, 007, 999
\wWord character [a-zA-Z0-9_]\w+hello, foo_bar
\sWhitespace (space, tab, newline)\s+spaces, tabs
^Start of string (or line with m flag)^HelloHello at start
$End of string (or line with m flag)world$world at end
*0 or more repetitions (greedy)ab*a, ab, abbb
+1 or more repetitions (greedy)ab+ab, abbb
?0 or 1 (optional)colou?rcolor, colour
{n,m}Between n and m repetitions\d{2,4}12, 123, 1234
(abc)Capture group(\d+)captures digits
(?:abc)Non-capture group(?:ab)+ab, abab
[abc]Character class[aeiou]any vowel
[^abc]Negated class[^aeiou]any consonant

You May Also Ask

What is the difference between greedy and lazy matching?
Greedy quantifiers (*, +, ?) match as much text as possible. Lazy quantifiers (*?, +?, ??) match as little as possible. For example, on the string <b>bold</b>: <.+> (greedy) matches the entire string, while <.+?> (lazy) matches <b> and </b> separately.
What are lookahead and lookbehind?
Lookahead (?=...) asserts that what follows the current position matches, without consuming characters. Lookbehind (?<=...) asserts what precedes. For example, \d+(?= dollars) matches a number only when followed by " dollars". They are called zero-width assertions because they don't consume text.
How do I match a newline?
By default, . does not match newlines. Enable the s (dotAll) flag to make . match newlines too. Alternatively, use [\s\S] which matches any character including newlines regardless of flags. In multiline mode (m flag), ^ and $ match line boundaries.

Common Mistakes

Forgetting to escape special characters
Characters like . * + ? ( ) [ ] { } ^ $ | \ have special meaning. Using them literally without a backslash gives unexpected matches — a dot matches any character, not a literal period.
Escape with backslash: \. \* \+ \? \( etc. when you mean a literal character.
Missing ^ and $ anchors for validation
Without anchors, a validation pattern like \d+ matches any string containing a digit — including "abc123xyz" which should fail validation.
Always use ^\d+$ for full-string matching in validation contexts.
Catastrophic backtracking with nested quantifiers
Patterns like (a+)+ or (\w+\s*)+ with alternation can cause exponential backtracking that freezes the browser or crashes servers on certain inputs.
Avoid nesting quantifiers. Use possessive quantifiers or atomic groups when available, or rewrite the pattern.