Regex Tester

// live match highlighting · capture groups · flags · common patterns · javascript regex engine

regular expression
/ /
enter a regex and test string
quick patterns
test string

What is a Regex Tester?

A regex tester lets you write and debug regular expressions against sample text in real time. It shows you exactly which parts of your string match, highlights capture groups, and tells you match positions — saving hours of trial-and-error in your code editor.

This tool uses JavaScript's native RegExp engine, so results are accurate for JS applications, Node.js backends, and browser-side validation.

How to use this tool

  • Type your regex in the top input (without slashes)
  • Toggle flags: g global, i case-insensitive, m multiline, s dotAll
  • Paste your test string — matches highlight instantly
  • Each match shows its value, index position, and capture groups
  • Use quick patterns below the regex input as starting points

Understanding regular expressions

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. They are used for string searching and manipulation across virtually every programming language. While the syntax can look intimidating at first, regular expressions are built from a small set of concepts that combine in powerful ways.

Literal characters match themselves — the regex cat matches the string "cat" anywhere in the text. Special characters called metacharacters have special meanings: . matches any character, * means zero or more of the preceding element, + means one or more, ? means zero or one, and ^ and $ anchor to the start and end of a line.

Character classes let you match any character from a set — [aeiou] matches any vowel, [0-9] matches any digit, and \w matches any word character (letter, digit, or underscore). Capture groups using parentheses let you extract specific parts of a match for further processing.

Regex flags explained

g (global) — Find all matches in the string instead of stopping after the first. Almost always what you want when testing patterns.

i (case insensitive) — Make the match ignore the difference between uppercase and lowercase letters. The pattern cat with the i flag matches "cat", "Cat", "CAT", and "cAt".

m (multiline) — Make ^ and $ match the start and end of each line rather than the entire string. Essential when working with multiline text.

s (dotAll) — Make the dot . match newline characters too. By default, . matches everything except newlines.

Frequently Asked Questions

What does the g flag do?+
The g (global) flag makes the regex find all matches in the string, not just the first one. Without it, the regex stops after the first match. Almost always enable this when testing — without g you'll only see match #1.
What are capture groups?+
Parentheses in a regex create capture groups — they let you extract specific parts of a match. For example, (\d{4})-(\d{2})-(\d{2}) matches a date and captures year, month, and day as separate groups. Named groups use the syntax (?<year>\d{4}).
What's the difference between . and \s?+
. matches any character except a newline (unless the s flag is set). \s matches any whitespace character: space, tab, newline, carriage return, form feed. Use \s+ to match one or more whitespace characters.
Why does my regex match too much?+
Quantifiers like * and + are greedy by default — they match as much as possible. Add ? after them to make them lazy (match as little as possible): .*? instead of .*. Also use anchors ^ and $ to restrict matches to the start/end of the string or line.
How do I match a literal dot or special character?+
Escape it with a backslash. \. matches a literal dot. \( matches a literal opening parenthesis. Special characters that need escaping: . * + ? ^ $ { } [ ] | ( ) \