Regex Tester & Replacement Preview
Write the pattern and watch the matches appear: enter your expression and flags at the top, put the test text on the left, and see every match highlighted on the right along with its position and capture groups.
Below that you can preview a replacement using $1 and $2 backreferences, so you can iterate without switching tools.
Features
- Live Highlighting — Matches are computed as you type and every hit is marked directly in the test text.
- Flag Toggles — g for global, i for case-insensitive, m for multiline, s for dot-matches-newline and u for Unicode, each switched independently.
- Match Details — Every match lists its text, start position and the value captured by each group.
- Replace Preview — Enter a replacement template and see the result immediately, with $1, $& and the rest of the substitution syntax.
- Common Patterns — Ready-made expressions for email addresses, phone numbers and URLs that you can drop in and adjust.
How to use
- Type the expression into the regex field and tick the g / i / m / s / u flags as needed.
- Paste the content to search into "Test text" on the left.
- Review the highlights and capture group details under "Matches" on the right.
- Switch to replace mode, enter a replacement template and check the preview.
FAQ
Which regex engine does this use?
The browser native JavaScript RegExp engine, following ECMAScript syntax. It is broadly compatible with Python, PCRE and Java, but features such as (?P<name>...) named groups and variable-length lookbehind differ, so keep that in mind when moving a pattern between languages.
Why does my pattern match nothing?
Three common causes: the g flag is off, so only the first occurrence can be found; special characters are unescaped — matching a literal dot requires \.; or m and s are unchecked, so ^, $ and . behave differently from what you expect.
What is the difference between greedy and lazy matching?
The quantifiers * and + are greedy by default and consume as much as possible. Appending a question mark makes them lazy (*? or +?), consuming as little as possible. Against <a><b>, the pattern <.+> matches the whole string while <.+?> matches only <a>.
Does the page record the patterns and text I enter?
No. Matching and replacement both run inside your browser, and your input is never sent to a server.
Does this page collect my data?
No. The content is either baked into the HTML at build time or every calculation runs locally in your browser, so your input is never sent to any server. Apart from the footer traffic counters (Baidu Analytics and our self-hosted visitor counter, see the privacy policy), this site collects nothing about your visit.
What is a regex that matches an email address?
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ covers the practical cases. The full RFC 5322 pattern is several times longer and still cannot tell you whether the mailbox exists, so most production systems validate with the short form and confirm ownership by sending a mail.
How do I use capture groups in the replacement?
Wrap the part you want with parentheses, then reference it in the replacement as $1, $2 in JavaScript and PHP, or \1, \2 in Python and sed. Named groups (?<year>...) are referenced as $<year> in JavaScript and \g<year> in Python, which stays readable once a pattern grows.
Why does my pattern work in one language but not another?
Dialects differ. JavaScript supports lookbehind only in recent engines, Python needs (?P<name>...) instead of (?<name>...), and \d matches non-ASCII digits under Python's Unicode mode but not in JavaScript without the u flag. Test in the target flavour, not just in a generic tester.
Can I test a regex without sending my pattern and text to a server?
Yes - every match on this page runs in your browser through the built-in engine, so the pattern and the test text never leave the device. The page has no endpoint that receives them, and it keeps working with the network disconnected after the first load.