How to use the Regex Tester
- Enter your regular expression and flags
- Paste a test string
- See matches, groups and replacements
Test regular expressions live
Type a regular expression and its flags (g, i, m, s, u, y), and every match in your test text is highlighted as you type, with a match count and a table of capture groups. Add a replacement (using $1 or $<name>) to preview the result. Ready-made patterns for email, URL, phone, date, IPv4, hex colour and numbers get you started. Everything runs in your browser.
JavaScript behaviour
The tester uses the browser's JavaScript engine, so results match JavaScript exactly โ named groups, lookbehind and Unicode property escapes such as \p{L} all work.
Other languages
Everyday syntax โ character classes, quantifiers, groups, alternation, anchors โ works the same in Python, Java, C#/.NET, PowerShell and R. Watch for these differences:
- Python writes named groups as
(?P<name>โฆ); use(?<name>โฆ)here. - Java and .NET support possessive quantifiers and atomic groups, which JavaScript doesn't.
- sed and grep use POSIX regex, which has no
\dor lookarounds โ use[0-9]instead.
Useful patterns
- Whole numbers:
^\d+$; decimals:-?\d+(\.\d+)? - Anything that isn't a letter, digit or space:
[^a-zA-Z0-9\s]
Quick reference
| Pattern | Matches |
|---|---|
\d \w \s | A digit, a word character (letter, digit, underscore), whitespace |
. | Any character except a line break (with the s flag, line breaks too) |
[abc] [^abc] | One of a, b or c; anything except a, b or c |
* + ? {2,5} | 0 or more, 1 or more, optional, between 2 and 5 times |
^ $ \b | Start of text, end of text, a word boundary |
(โฆ) (?:โฆ) (?<name>โฆ) | Capture group, group without capturing, named group |
(?=โฆ) (?!โฆ) (?<=โฆ) | Followed by, not followed by, preceded by |
Flags
g finds every match instead of the first one. i ignores case. m makes ^ and $ match at the start and end of each line. s lets . match line breaks. u turns on full Unicode, needed for \p{L}. y only matches at the exact position where the last match ended, and d records where each group starts and ends.
Common mistakes
- Greedy matching.
<.+>on "<b>hi</b>" matches the whole string. Add?to make it lazy:<.+?>matches each tag separately. - Unescaped dots.
example.comalso matches "exampleXcom". Writeexample\.com. - Only one match. Without the
gflag, only the first match is found and replaced.
Frequently asked questions
Why does my regex only find the first match?
The g (global) flag is missing. Add g in the Flags box to find and replace every match.
How do I match across several lines?
Use the m flag so ^ and $ work on every line, and the s flag if you need . to match line breaks as well.
Is this the same as regex in Python?
Mostly. Everyday patterns work the same, but Python writes named groups as (?P<name>...) and has some differences in flags. This tester follows JavaScript exactly.