Regex Tester — Test Regular Expressions Online
Regular expressions (regex) are patterns that describe sets of strings, used everywhere from form validation and log searching to text refactoring in editors. This tester compiles your pattern with the JavaScript regex engine, runs it against your sample text as you type, and highlights every match in place. Capture groups are listed for each match, so you can see exactly which parts of the text your parentheses extracted.
Writing regex is famously trial-and-error: a pattern that looks right can match too much, too little, or nothing at all. Testing against real sample data before shipping the pattern to production code catches these surprises early. Common presets — email, URL, phone number, date — give you a working starting point you can adapt instead of building from scratch.
How it works
The pattern is compiled with the browser's native RegExp engine (ECMAScript flavor) together with the flags you select: g (find all matches, not just the first), i (case-insensitive), m (^ and $ match at line breaks), s (dot matches newlines), and u (Unicode mode). The compiled expression is executed against the sample text; each match's position, matched text, and numbered or named capture groups are read from the resulting match objects and highlighted.
Use cases
- Building and debugging a validation pattern for emails, phones, or postal codes before adding it to a form
- Testing a search pattern against sample log lines before running it across production logs
- Extracting data with capture groups — dates, IDs, URLs — from semi-structured text
- Understanding what an inherited regex in a codebase actually matches
- Preparing find-and-replace patterns for editors and IDEs
- Learning regex syntax interactively by watching matches update as you type
Frequently asked questions
Which regex flavor does this tester use?
It uses the JavaScript (ECMAScript) regex engine built into your browser, the same flavor used in Node.js and front-end code. Most syntax carries over to PCRE (PHP, and similar to Python's re module), but there are differences: lookbehind support varies by engine, and JavaScript uses (?<name>...) for named groups. If your pattern targets another language, verify engine-specific features in that environment too.
What do the regex flags g, i, m, s, and u mean?
g (global) finds all matches instead of stopping at the first. i (ignore case) makes the pattern case-insensitive. m (multiline) makes ^ and $ match at the start and end of each line rather than the whole text. s (dotAll) lets the dot match newline characters. u (unicode) enables full Unicode handling, including \p{...} property escapes for matching categories like letters or digits in any script.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, {n,}) match as much text as possible while still allowing the overall pattern to succeed; lazy ones (*?, +?) match as little as possible. The classic example is <.+> against HTML: greedy matching grabs from the first < to the last >, swallowing everything between tags, while <.+?> stops at the first closing bracket. When a pattern matches more than you expect, a greedy quantifier is the usual culprit.
What are capture groups in a regular expression?
Parentheses in a pattern create capture groups, which store the exact substring matched by that part of the expression. Groups are numbered left to right from 1 (group 0 is the whole match), and can be named with the (?<name>...) syntax. They are how you extract structured data — for example, (\d{4})-(\d{2})-(\d{2}) captures the year, month, and day of an ISO date as three separate groups.
Is there a regex that validates every email address?
Not practically. The full RFC 5322 grammar for email addresses is so permissive that a complete regex is enormous and still would not confirm the mailbox exists. In practice, a pragmatic pattern such as one requiring text, an @, a domain, and a dot-separated TLD catches typos, and a confirmation email verifies deliverability. That is also how most frameworks and browsers approach email validation.