Regex Tester — Match, Replace, and Common Patterns
Test regular expressions against sample text in your browser. Matches highlight as you type. Switch to replace mode to rewrite text with $1, $<name>, and $& tokens. Load common patterns (email, URL, IPv4, date, phone, hex color) and open the flags cheat sheet for g, i, m, s, u, y, and d. Nothing leaves your device.
Flags and syntax cheat sheet
Flags
gglobalFind every match, not just the firstiignore caseCase-insensitive matchingmmultiline^ and $ match line starts and endssdotAll. matches newline charactersuunicodeUnicode code points and \p{} propertiesystickyMatch only at lastIndexdhasIndicesInclude match start/end indices
Syntax
.Any character except newline (unless s)\dDigit, same as [0-9]\wWord character [A-Za-z0-9_]\sWhitespace* + ?0+, 1+, or optional^ $Start / end of string (or line with m)\bWord boundary( )Capturing group(?: )Non-capturing group(?<n> )Named capturing group$1Replace with group 1$&Replace with the whole match$<n>Replace with named group n
Full reference: Regex cheat sheet
What is a regular expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. Engines interpret special characters like . (any character), * (zero or more), + (one or more), and [] (character class) to match text patterns. See: MDN Regex Guide.
Why Use This Tool
- Validate input — Load the email, URL, or phone pattern and test real strings.
- Parse logs — Extract timestamps, IP addresses, or error codes from log files.
- Find and replace — Rewrite matches with capture tokens, then copy the result. Compare changes →
- Data extraction — Pull specific fields from structured text using groups.
- Learn flags and syntax — Use the in-tool cheat sheet for g, i, m, s, u, y, d and common tokens.
Tips
- Start with a library pattern, then edit it.
- Use $& when you want to wrap the whole match rather than a group.
- Turn g off when you only want the first match or first replacement.
- Open the cheat sheet for u (unicode), y (sticky), and d (indices).
- The full syntax guide lives at /guides/regex-cheat-sheet.
How to Use the Regex Tester
Enter a pattern or pick a library item
Type a regex, or click Email, URL, IPv4, date, phone, or hex color to load a sample.
Set flags
g finds every match. i ignores case. m, s, u, y, and d are listed in the cheat sheet.
Match or replace
Match mode highlights hits. Replace mode applies $1, $<name>, and $& to a live output.
Copy the result
In replace mode, copy the rewritten text. Capture groups stay visible below.
Worked Examples
Match digits
Pattern: \d+ Text: "Order 12345"
Match: 12345
Email from the pattern library
[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,} with flag iMatches: Ada@example.com
Replace with a named group
Pattern: (?<year>\d{4})-(\d{2})-(\d{2})
Replacement: $<year>/$2/$32024-01-15 → 2024/01/15
Whole-match token
Pattern: \w+ Replacement: [$&]
hello world → [hello] [world]
Common Errors & How to Fix Them
| Error Message | Cause | Fix |
|---|---|---|
Invalid regular expression | Syntax error in the pattern | Check for unmatched parentheses, brackets, or invalid escape sequences. |
Nothing matches | Pattern does not match any text | Verify the pattern and test text. Check if flags like i (case-insensitive) are needed. |
Too many matches / slow | Pattern causes catastrophic backtracking | Avoid nested quantifiers like (a+)+. Simplify the pattern and keep the global flag only when needed. |
Common Regex Tokens
| Feature | Token | Meaning |
|---|---|---|
| . | Any character | Except newline (unless s flag) |
| \d | Digit | Same as [0-9] |
| \w | Word character | Same as [A-Za-z0-9_] |
| \s | Whitespace | Space, tab, newline |
| $1 | Replace group 1 | $& is the whole match |
| $<name> | Replace named group | Requires (?<name>…) |
| g | Global flag | All matches / all replacements |
| u | Unicode flag | Code points and \p{} properties |
Frequently Asked Questions
What is a regex tester?
A regex tester lets you write a regular expression and try it against sample text. This one highlights matches, can replace them, and ships a pattern library plus a flags cheat sheet.
How does replace mode work?
Enter a replacement string. $1, $2 insert numbered capture groups, $<name> inserts a named group, and $& inserts the whole match. With the g flag every match is replaced; without it only the first match changes.
Does this regex tester work for JavaScript?
Yes. It uses the JavaScript RegExp engine, including flags g, i, m, s, u, y, and d (hasIndices).
Can I use this regex tester for Python?
JavaScript and Python regex are similar but not identical. Most basic patterns work in both. Named groups and some escapes differ.
What does the global flag (g) do?
The g flag finds or replaces every match instead of stopping after the first.
Does this regex tester upload my data?
No. Matching and replacing run in your browser with JavaScript RegExp. Nothing is sent to a server.