Regex Tester
Free Online Regular Expression Test Tool
Type a JavaScript regular expression and test it against your text. Matches are highlighted in real time with capture groups and an optional replace preview.
Match Highlighting
0 matchesMatches & Capture Groups
Replace Test
How to Use the Regex Tester
1. Enter Your Regex
Type your regular expression in the pattern box. Use JavaScript regex syntax, such as \b\w+@\w+\.\w+\b for email addresses.
2. Choose Flags
Toggle flags to change matching behavior: g (all matches), i (ignore case), m (multiline), s (dotAll), and u (unicode).
3. Paste Test Text
Add the text you want to search. Matches are highlighted instantly and listed with their capture groups.
4. Test Replacements
Enter a replacement pattern (e.g. $1) to preview what a substitution would produce.
What is a Regular Expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. Regex is used to match, find, and manipulate text in virtually every programming language, including JavaScript, Python, and Java.
Common patterns include \d+ for numbers, \w+ for words, ^ and $ for anchors, and parentheses ( ... ) to capture groups. Our tester evaluates your pattern with the native JavaScript RegExp engine so the results match what you get in the browser.
Build a Pattern Step by Step: Dates in a Log
The best way to write a regular expression is to grow it a piece at a time and watch the highlights. Paste this sample into the test text box:
2026-10-28 09:14:02 INFO order 1182 shipped
2026-10-28 09:15:47 ERROR payment 1183 declined
28/10/2026 legacy line without ISO date
2026-10-29 00:01:10 WARN retry queue at 85%
- Start with
\d{4}and thegflag. Every four-digit run lights up, including1182and2026inside the legacy line. Too broad. - Extend to
\d{4}-\d{2}-\d{2}. Now only the three ISO dates match. - Anchor it to the start of a line:
^\d{4}-\d{2}-\d{2}. With onlygon, you get one match, because^means "start of the whole text". Turn onm(multiline) and^means "start of each line": three matches again, and nothing in the middle of a line can sneak in. - Add groups to pull out parts:
^(\d{4})-(\d{2})-(\d{2}) [\d:]+ (ERROR|WARN). The match list shows groups 1–4 for the two lines that have a problem level. - In the replacement box type
$3/$2/$1 $4. The preview rewrites the ERROR line as28/10/2026 ERROR payment 1183 declined.
Flags, and When You Need Each
| Flag | Effect | Turn it on when |
|---|---|---|
g | Find every match, not just the first | Almost always while testing; also needed for replace-all |
i | Ignore upper/lower case | Matching words like "error", "Error", "ERROR" |
m | ^ and $ match at every line break | Processing text line by line, such as logs or CSV |
s | . also matches newlines | Grabbing a block that spans lines, like an HTML comment |
u | Full Unicode mode | Emoji, \p{L} letter classes, or strict syntax checking |
Patterns Worth Keeping
- Hex colour:
#(?:[0-9a-fA-F]{3}){1,2}\bmatches#fffand#3B82F6. - Trailing whitespace:
[ \t]+$withmfinds spaces at line ends; replace with nothing. - Duplicate words:
\b(\w+)\s+\1\bwithicatches "the the". - Key=value pairs:
(\w+)=("[^"]*"|\S+)splitsuser=ana role="team lead". - A practical email check:
^[^\s@]+@[^\s@]+\.[^\s@]+$. It rejects obvious typos without pretending to implement the full RFC 5322 grammar, which no sensible regex does.
Why a Pattern Works Here but Not in Your Code
This tester runs your pattern through the browser's own JavaScript RegExp engine, so results match Node.js and front-end code exactly. Other languages have their own dialects:
- Escaping in strings. In Java, C# or Python source code,
\dmust be written"\\d"unless you use a raw string (r"\d"in Python). Here you type the pattern itself, without string quotes. - Greedy quantifiers.
<.+>on<b>bold</b>matches the whole thing. Add?to make it lazy:<.+?>matches each tag. - Features that differ. Possessive quantifiers (
a++) and atomic groups work in Java and PCRE but not in JavaScript; lookbehind works in modern JavaScript but not in some older engines. - Catastrophic backtracking. Nested quantifiers such as
(a+)+$can take exponential time on input that almost matches. If the page freezes while you type, that is what happened; rewrite the pattern without nested repetition.
Related Tools
When the text you are searching is structured data, a parser beats a regex: format and inspect it with the JSON Formatter. To count words or characters in a block before and after a replacement, use the Word Counter. If a pattern has to match encoded URLs, decode them first with the URL Encoder. See all developer tools.
Frequently Asked Questions
Which regex flavor does this tester use?
JavaScript (ECMAScript) regular expressions, evaluated by your browser's built-in RegExp engine.
Why does ^ only match the first line?
Without the m flag, ^ and $ refer to the start and end of the entire text. Turn on multiline (m) to make them match at each line.
How do I reference a capture group in the replacement?
Use $1, $2 and so on for numbered groups, $& for the whole match, and $<name> for a named group written as (?<name>...).
How do I match a literal dot or bracket?
Escape it with a backslash: \. matches a dot, \( a parenthesis and \[ a square bracket.
Is my test text uploaded?
No. Matching and replacing run entirely in your browser.