Regex Tester
Enter a pattern and some test text, and see exactly what it matches — useful for building a regex from scratch or figuring out why an existing one isn't working.
Overview
Regular expressions are compact but easy to get subtly wrong — a quantifier in the wrong place, a forgotten escape character, or a missing flag can silently change what a pattern matches. Rather than testing a pattern by running it inside actual application code, this tool lets you iterate on a pattern and test text side by side and see results immediately, which is faster for exploring how a regex behaves.
Matching uses JavaScript's native RegExp engine — the same one that runs in every browser and in Node.js. That means what you see here is exactly how the pattern will behave in real JavaScript code, not an approximation from a different regex flavor. If you're writing a pattern for a `.match()`, `.test()`, or `.replace()` call, or a validation rule in a form, this is the same engine that will run it.
Flags change matching behavior and are easy to forget: `g` (global) finds every match instead of stopping at the first, `i` (case-insensitive) ignores letter case, `m` (multiline) changes how `^` and `$` behave across line breaks, and `s` lets `.` match newlines. Getting an empty or unexpected result is very often a missing flag rather than a wrong pattern.
Examples & Sample Data
Named and numbered capture groups
Pattern: (?<year>\d{4})-(\d{2}) Flags: g Text: Released 2024-05 and 2025-11
2 matches. Match 1 at 9–16: "2024-05" $<year> = "2024", $2 = "05" Match 2 at 21–28: "2025-11" $<year> = "2025", $2 = "11"
Find and replace with group references
Pattern: (?<year>\d{4})-(\d{2}) Flags: g Replace with: $2/$<year> Text: Released 2024-05 and 2025-11
Released 05/2024 and 11/2025
How It Works
- Enter your pattern between the slashes, without the surrounding slashes themselves.
- Tick the flags you need: g for every match, i to ignore case, m for line-by-line ^ and $, s so . matches newlines, u for Unicode, and y for sticky matching.
- Paste or type the text to test against. Matches are highlighted as you type.
- Read the match details table for each match's position and the value of every numbered and named capture group.
- Optionally enter a replacement, using $1, $<name>, or $& for the whole match, to preview the replaced text and copy it.
Common Use Cases
Validating user input
Test a pattern intended for form validation (email format, phone number, postal code) against a range of valid and invalid sample inputs before putting it into code.
Extracting data from text
Build a pattern to pull specific values — IDs, dates, URLs — out of log lines or unstructured text, and confirm it captures every instance.
Debugging an existing regex
Paste in a pattern from existing code that isn't matching as expected, and test it against real sample text to see exactly where it diverges.
Learning regex syntax
Experiment with quantifiers, character classes, and groups against small test strings to see their effect immediately, without writing and running code.
Tips & Best Practices
- Without the "g" flag, a pattern only reports its first match, even if the text contains more.
- Special characters like `.`, `*`, `+`, `?`, `(`, and `)` need to be escaped with a backslash if you want to match them literally.
- `^` and `$` match the start and end of the whole string by default — add the "m" flag if you need them to match the start and end of each line instead.
- Greedy quantifiers like `.*` match as much as possible; add `?` after them (`.*?`) to match as little as possible instead.
- If a pattern matches nothing, test a much simpler version of it first, then add complexity back piece by piece to find where it breaks.
- Watch for nested quantifiers like (a+)+ or (.*)*. On text that almost matches, they can take exponentially long, which is the classic cause of regex-based denial of service.
Frequently Asked Questions
No. Matching runs entirely in your browser using JavaScript's native RegExp engine.
JavaScript's (ECMAScript) regex flavor — the same engine your browser and Node.js use. Syntax can differ slightly from PCRE, Python, or other flavors.
Check your flags — a pattern without the "g" flag only reports the first match, and case sensitivity depends on the "i" flag.
Yes. The match details table lists every match with its start and end position and the value of each numbered group, or "(not matched)" for an optional group that didn't take part.
Yes. Named groups written as (?<name>...) appear in the match details table, and you can reference them in the replacement as $<name>.
Matching runs in a background worker with a 1.5-second limit. A pattern that backtracks catastrophically, such as nested quantifiers like (a+)+, is stopped with an explanation instead of freezing the page.
Yes. Enter a replacement string to see the result of JavaScript's String.replace with your pattern and flags. Use $1 or $<name> for groups and $& for the whole match.
Related Tools
Explore more high-performance utilities.