Regex Tester
Enter a pattern and flags, paste your test string, and see matches highlighted live — with capture groups, a match count, and a replace preview. Runs entirely in your browser.
Dialect: JavaScript (ECMAScript) RegExp — behavior may differ from PCRE, Python re, or other regex engines.
Enter a pattern to start matching.
Highlighted matches
Matches will be highlighted here once you enter a test string.
Match details
Replace preview
Only the first match is replaced — check the g flag to replace every match.
Testing regular expressions in JavaScript
A regular expression (regex) is a compact pattern for finding, validating, or replacing text. This tester runs your pattern with the browser's own RegExp engine and updates as you type: matches are highlighted, each is listed with its position and captured groups, and a live count shows how many were found. Because it uses the native engine, what you see here is exactly what the same pattern will do in JavaScript code.
Enter the pattern without the surrounding slashes, tick the flags you need, and paste your text into the test box. The dialect matters: this tool tests the JavaScript (ECMAScript) flavour, which differs from PCRE (used by PHP and many command-line tools) and from Python's re module. Features such as recursive patterns, atomic groups, and possessive quantifiers do not exist in JavaScript, so a pattern copied from another language may behave differently here.
What the flags do
| Flag | Name | Effect |
|---|---|---|
| g | Global | Find every match, not just the first |
| i | Ignore case | Treat A and a as the same |
| m | Multiline | ^ and $ match each line's start and end |
| s | Dotall | The dot also matches newline characters |
| u | Unicode | Full code-point matching and \p{...} escapes |
| y | Sticky | Match only at the current position |
The most common surprise
By far the most frequent confusion is a replace that changes only the first match. In JavaScript, replacing every occurrence requires the g flag — without it, only the first match is replaced, and that is the language rule, not a bug. The replace preview here mirrors that exactly, and a hint appears reminding you to add g whenever your pattern would otherwise stop after one substitution.
Handy tokens and a privacy note
- \d \w \s match a digit, a word character, and whitespace; their uppercase forms (\D \W \S) match the opposite.
- ^ and $ anchor to the start and end of the input; add the m flag to anchor per line instead.
- Quantifiers like * + ? and {2,4} are greedy by default; add a trailing ? (for example .+?) to make them lazy.
- Character classes in square brackets match any one listed character — [aeiou] matches a single vowel, and a leading caret negates it, so [^0-9] matches anything that is not a digit.
- Alternation with the pipe tries each option in turn — cat|dog matches either word — and round brackets group a sub-pattern so a quantifier can apply to the whole group.
Your pattern, test string, and replacement never leave your browser — nothing is uploaded, and only your last input is kept locally for convenience.
Sources & further reading
Frequently asked questions
How do I test a regular expression online for free?
Type or paste your pattern into the pattern field (without the surrounding slashes), tick the flags you need — g for global, i for case-insensitive, and so on — then paste your text into the test string box. This regex tester matches live as you type: every match is highlighted in the preview, listed with its start index and captured groups below, and the match count updates instantly. For example, entering the pattern \b\w+@\w+\.\w+\b against "Contact us at hello@example.com or sales@example.org" highlights both email addresses immediately, no submit button needed.
What do the regex flags g, i, m, s, u, and y mean in JavaScript?
g (global) finds every match instead of stopping at the first; i (ignore case) makes A and a equivalent; m (multiline) makes ^ and $ match the start and end of each line instead of only the whole string; s (dotall) lets . match newline characters too; u (unicode) enables full Unicode code-point matching (needed for things like emoji or astral characters and for \p{...} Unicode property escapes); and y (sticky) forces the match to start at exactly the current position (lastIndex) rather than scanning ahead. This tool lets you toggle each one and see the effect on your matches immediately.
Why does my regex only replace the first match?
In JavaScript, String.prototype.replace() only replaces every occurrence when the regular expression has the g (global) flag — without it, only the first match is replaced, which is standard ECMAScript behavior, not a bug. This regex tester mirrors that exact rule: the replace preview shows what your pattern and replacement actually produce with your current flags, and a hint appears reminding you to check g if you expected every match to change. Turn on g and the preview updates to show every match replaced.
How do named capture groups like (?<year>\d{4}) work in JavaScript regex?
Wrapping part of a pattern in (?<name>...) creates a named capture group alongside the normal numbered groups — for example (?<year>\d{4})-(?<month>\d{2}) matched against "2026-07" captures group 1 / "year" as 2026 and group 2 / "month" as 07. Named groups can also be referenced in a replacement string as $<year>, which is often clearer than $1 in longer patterns. This tester lists both the numbered groups and the named groups for every match, so you can confirm the capture works before using it in real code.
Is my regex pattern or test string sent to a server, and does this match every regex dialect?
No — everything runs locally using your browser's built-in RegExp engine; your pattern, test string, and replacement text are never uploaded or stored anywhere, and nothing is saved except your last input in your own browser's local storage for convenience. This tool tests the JavaScript (ECMAScript) regex dialect specifically, so a pattern that relies on PCRE-only or Python re-only features (like recursive patterns, atomic groups, or possessive quantifiers) may behave differently here than in those languages — check your target language's own documentation if you are writing regex for something other than JavaScript.