Regex Tester
Free regex tester. Test JavaScript regular expressions live with highlighted matches, capture groups, and flag toggles — i, g, m, s, u, y all supported.
Quick answer
Regex (regular expression) is a pattern language for matching strings. \d+ matches one or more digits. [A-Z] matches one uppercase letter. (foo|bar) matches 'foo' or 'bar'. The tester runs your pattern against any input live and highlights matches.
Regex Tester
Matches
How it works
Compiles your pattern as a JavaScript RegExp with the flags you specify, then runs matchAll against your test string and lists every match with its position. Common flags: g (global, find all matches), i (case-insensitive), m (multiline, ^ and $ match line boundaries), s (dotall, . matches newlines).
When to use it
Testing patterns before pasting them into code, validating user input formats, extracting data from messy text, or learning regex by experimenting.
Common mistakes
Forgetting to escape literal special characters — to match a real period, write \., not . (which matches anything). JavaScript regex has minor differences from Python or PCRE; don't assume patterns from other languages work as-is.
How the regex tester works
You enter a regex pattern (without the surrounding slashes), pick flags (g for global, i for case-insensitive, m for multiline, s for dotall), and a test input. The tool runs the JavaScript RegExp engine against the input and highlights every match. For patterns with capture groups, each group's value is displayed alongside the match. Invalid patterns show a parse error so you can fix syntax before running.
When to use it
Building input validation patterns (email addresses, phone numbers, postal codes). Extracting structured data from log lines, scraped HTML, or unstructured text. Refining a regex iteratively against real test data before shipping it to production code. Learning regex syntax — type a pattern, watch what it matches, adjust.
Common mistakes
- Forgetting that
.doesn't match newlines by default. The dot matches any character except newline unless the 's' (dotall) flag is set. - Greedy vs. lazy quantifiers.
.*is greedy — it matches as much as possible..*?is lazy — it matches as little as possible. Use lazy when matching paired delimiters like quotes or HTML tags. - Anchors silently doing nothing without the right flags. ^ matches start of string by default; with the m (multiline) flag, it matches start of each line. Same for $.
- Trying to parse HTML with regex. Don't. HTML's recursive structure isn't regular. Use a real parser.
Frequently asked questions
What is a regular expression?
A regex (regular expression) is a pattern language for describing sets of strings. \d matches a digit, [a-z] matches a lowercase letter, .* matches anything. Regex powers find-and-replace, validation, and text extraction across virtually every programming language.
What's the difference between . and \.?
. (unescaped) is a regex wildcard — it matches any single character except newline. \. (escaped with backslash) matches a literal dot character. To match a period in 'example.com', you need \..
Why is my regex matching too much?
Almost always greedy quantifiers. .* matches as much as possible — including past the closing delimiter you intended. Switch to lazy: .*?. For matching paired delimiters cleanly, use a more specific pattern like [^"]* instead of .*.