Regex Tester
Test regular expressions online with live match highlighting and groups.
Runs in your browser. Nothing is uploaded.
What is Regex Tester?
A regular expression, or regex, is a compact pattern for finding and changing text. Developers use regexes to validate input such as email addresses and dates, to pull values out of logs, to search code and to clean up data. They are powerful but easy to get wrong, which is why a regex tester that shows what a pattern matches while you type is one of the most useful tools you can keep open.
This regex tester uses your browser's JavaScript regular expression engine, the same one your code runs. Type a pattern, switch flags on and off, and paste the text to test. Every match is highlighted as you type, and a table lists each match with its position and the value of every capture group, with named groups shown by name. A replace mode previews the result of substitutions that use $1, named references and $&, and you can copy the finished pattern as a JavaScript literal, a new RegExp call or a JSON string.
Patterns that backtrack catastrophically can freeze a page, so matching runs in a background worker that is stopped after one second, and you get a clear message instead of a hung tab. Invalid patterns show the reason in plain words. Everything runs in your browser and nothing you enter is uploaded, so it is safe to test against real logs and data.
How to use
- Type your pattern in the box between the slashes, or load one of the common examples such as an email address or a date.
- Turn flags on or off. The g flag finds every match, i ignores case, m and s change how line breaks work, and u enables full Unicode.
- Paste or type the text to test. Matches are highlighted below and listed with their capture groups.
- Optionally tick Replace matches to preview a substitution using $1, $<name> or $&.
- Copy the pattern as a regex literal, a new RegExp call or a JSON string when you are happy with it.
Example
Input
Pattern: (?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+) Text: Write to ada@example.com today
Output
Match: ada@example.com (position 9 to 24) user = ada domain = example.com
Regex cheat sheet
The most common JavaScript regular expression syntax at a glance.
| Syntax | Meaning |
|---|---|
. | Any character except a line break (with the s flag, any character) |
\d \w \s | A digit, a word character (letter, digit or underscore), a whitespace character |
\D \W \S | The opposite of \d, \w and \s |
\b | A word boundary |
^ $ | Start and end of the text (of each line with the m flag) |
[abc] [^abc] [a-z] | Any of these characters, none of these characters, or a range |
a* a+ a? | Zero or more, one or more, zero or one |
a{3} a{2,5} | Exactly 3, or between 2 and 5 |
a*? a+? | Lazy versions that match as little as possible |
(abc) | A capture group |
(?<name>abc) | A named capture group, used as $<name> when replacing |
(?:abc) | A group that does not capture |
a|b | Either a or b |
(?=a) (?!a) | Lookahead: followed by a, not followed by a |
(?<=a) (?<!a) | Lookbehind: preceded by a, not preceded by a |
\1 \k<name> | A backreference to an earlier group |
\p{L} | A Unicode letter (needs the u flag) |
Frequently asked questions
- Which regex flavour does this tester use?
- It uses JavaScript regular expressions, the engine built into your browser, so results match what your JavaScript or TypeScript code and most Node.js programs will do. Other languages such as Python or PCRE differ in a few features.
- Why does my pattern say it took too long?
- Some patterns, usually with nested repetition such as (a+)+, can take exponentially longer as the text grows, which is called catastrophic backtracking. The tester stops them after one second. Make the pattern more specific or remove the nested quantifiers.
- What do the regex flags mean?
- The g flag finds all matches instead of the first, i ignores upper and lower case, m makes ^ and $ match at every line, s lets the dot match line breaks, u turns on full Unicode support, y matches only at the current position, and d records the exact positions of groups.
- Is my text sent to a server?
- No. The pattern and the text are processed entirely in your browser, in a background worker, and nothing is uploaded.
Related tools
- Case ConverterConvert text to camelCase, snake_case, kebab-case and more.
- Text Diff CheckerCompare two texts online and see added and removed lines side by side.
- JSON Formatter & ValidatorFormat, minify and validate JSON online with line-accurate error messages.
- Base64 Encode / DecodeBase64 encode and decode text with full UTF-8 and URL-safe support.