Regex Tester Online: Test Regular Expressions with Matches, Groups and Replace
Type a pattern and flags, paste the text to search, and the tester lists every match with its position and the value of each capture group, numbered (`$1`, `$2`) and named. Fill in Replace with to preview a substitution, using `$1` or `$<name>` to insert groups. The tester uses your browser's JavaScript regex engine, the same one that runs your front-end and Node.js code, so what matches here matches there.
How to use the tester
Write the pattern without the surrounding slashes: #(\d+) rather than /#(\d+)/g. Put flags in the Flags field. The tester always searches for all matches, so you do not need g to see them; the flags you enter still apply to the replace preview, where they matter.
Pattern: #(\d+)
Text: Order #1042 shipped 2026-09-21, order #1043 pending.
#1042 at 6 $1: 1042
#1043 at 38 $1: 1043
The position is the zero-based index of the first character of the match, the same value as match.index in JavaScript. An invalid pattern shows the engine's error message, such as Unterminated group or Duplicate capture group name, instead of results. To keep the page responsive, at most 500 matches are listed.
A match list full of empty entries means the pattern can match nothing at all: \d* against ab returns three empty matches, one at each position. Change * to +, or anchor the pattern, and the noise disappears.
Flags
g global: find all matches (for replace: replace all, not just the first)
i ignore case
m multiline: ^ and $ match at every line break, not only at the ends of the text
s dotAll: . also matches line breaks
u Unicode: code points, \p{…} property escapes, stricter syntax
v unicodeSets: u plus set operations in classes (ES2024)
y sticky: match only at lastIndex
d indices: record start and end positions of groups
Two flags cause most surprises. Without m, ^ and $ match only at the very start and end of the whole text, so a pattern meant to validate each line of a pasted list matches nothing. Without s, . stops at line breaks, so <div>.*</div> fails across lines.
An unknown or repeated flag makes the whole regex invalid: gg or x gives Invalid flags supplied to RegExp constructor. The x flag for comments exists in PCRE and Python but not in JavaScript.
Regex cheat sheet
. any character except line breaks (with s: any character)
\d \w \s digit, word character [A-Za-z0-9_], whitespace
\D \W \S the opposites
[abc] [^abc] [a-z] character class, negated class, range
^ $ start and end of text (with m: of each line)
\b word boundary
* + ? 0 or more, 1 or more, 0 or 1 (greedy)
*? +? ?? the same, lazy: as few as possible
{3} {2,5} {2,} exact, range, at least
(…) capture group (?<name>…) named group
(?:…) group without capturing
a|b alternation
(?=…) (?!…) lookahead, negative lookahead
(?<=…) (?<!…) lookbehind, negative lookbehind
\1 \k<name> backreference to a group
Escape the characters . * + ? ^ $ { } ( ) | [ ] \ / with a backslash when you mean them literally: \. matches a dot, while . matches anything. Inside a character class most of them lose their special meaning, so [.] also matches a literal dot.
If you keep a Python regex cheat sheet next to this one, the differences are few but they bite: named groups are (?P<name>…), the absolute end of the string is \Z (and \z since Python 3.14), replacements use \1 and \g<name>, and \d and \w match any Unicode digit or letter unless you pass re.ASCII.
Testing a replacement
Replace with shows the result of text.replace(pattern, replacement) using your flags. Without g, only the first match is replaced, exactly as in JavaScript; add g to replace all. In the replacement, $1 inserts the first group, $<name> a named group, $& the whole match and $$ a literal dollar sign.
Pattern: (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})
Replace: $<d>.$<m>.$<y>
Result: Order #1042 shipped 21.09.2026, order #1043 pending.
Other languages write replacements differently: Python and sed use \1 and \g<name>, and a Python-style replacement pasted into JavaScript inserts the literal text \1. Check the replacement syntax of the language you will use.
Differences between regex flavours
Most syntax is shared between JavaScript, PCRE (PHP), Python, Java, .NET and Go, but not all of it. \w and \d are ASCII-only in JavaScript even with the u flag, while Python 3 and .NET match Unicode letters and digits by default, so ^\w+$ matches café in Python and not here; use \p{L} with the u flag for letters in any script. Python's re module writes named groups as (?P<name>…) and rejects the (?<name>…) form that JavaScript, PCRE, Java and .NET use. Go's RE2 engine has no lookarounds or backreferences, trading them for guaranteed linear time.
Possessive quantifiers (a++) and atomic groups ((?>…)) exist in PCRE and Java but not in JavaScript. When a pattern will run in another language, keep to the common subset or test it in that language too.
Avoiding slow and wrong patterns
Nested quantifiers such as (a+)+$ or (\w+\s?)*$ can take exponential time on input that almost matches, which freezes a browser tab or a server thread. This is called catastrophic backtracking, and it is the cause of ReDoS vulnerabilities. Make repeated parts mutually exclusive, anchor patterns, and set input length limits before running regexes on user data.
For validation, anchor both ends: \d{5} finds five digits inside abc123456, while ^\d{5}$ accepts only exactly five digits. Test with inputs that should fail as well as ones that should pass: empty strings, extra spaces, very long inputs and characters from other alphabets.
You do not need a regex generator for most patterns. Start from one real example and generalise it a piece at a time: paste a sample line, type it literally as the pattern, then replace each variable part with a class or quantifier, 2026 with \d{4}, ORD with [A-Z]{3}, and watch the match count after each change. When the count jumps, the last edit made the pattern too loose.
Frequently asked questions
How do I test a regex online?
Enter the pattern without slashes, add flags such as i or m, and paste your text. Every match is listed with its position and capture groups, and errors in the pattern are shown immediately.
Which regex engine does the tester use?
Your browser's JavaScript (ECMAScript) engine, the same as in front-end code and Node.js. Most syntax matches PCRE, Python and Java, with differences in Unicode handling, named groups and advanced features.
Why does my regex only match the first line?
Without the m flag, ^ and $ match only at the start and end of the whole text. Add m to make them match at each line break.
How do I use capture groups in a replacement?
Use $1, $2 for numbered groups and $<name> for named groups in the Replace with field. Add the g flag to replace every match rather than only the first.
Why does \w not match accented letters?
In JavaScript, \w is always [A-Za-z0-9_]. Use \p{L} with the u flag to match letters in any language.
Is my text sent to a server?
No. Matching and replacing run in your browser, and nothing is uploaded or stored.