How to use the regex tester
- 1Type the pattern into Pattern, without the surrounding slashes, or pick one from Pattern library.
- 2Tick the Flags you need: g for every match, i to ignore case, m for per-line
^and$, s so.matches new lines, u for Unicode. - 3Paste your text into Test text. Matches are underlined in Matches, and Match details lists the position and every capture group.
- 4To try a substitution, tick Show a replace preview and type into Replace with, using
$1or$<name>. Press Copy to take the result.
Example
Pattern: (?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+) Flags: g Text: Write to ada@example.com or grace.hopper@navy.mil. Replace with: $<user> at $<domain>
2 matches: ada@example.com (user = ada, domain = example.com), grace.hopper@navy.mil (user = grace.hopper, domain = navy.mil) Replace result: Write to ada at example.com or grace.hopper at navy.mil.
Flags: g, i, m, s, u, y
| Flag | Name | Effect |
|---|---|---|
g | global | Find every match, not just the first. Replace changes all of them. |
i | ignore case | cat matches Cat and CAT. |
m | multiline | ^ and $ match at the start and end of each line, not only of the whole text. |
s | dotAll | . also matches line breaks. |
u | unicode | Treats emoji as one character and enables \p{L} style property classes. |
y | sticky | Each match must start exactly where the previous one ended. |
Without g, the tester shows only the first match, just as String.prototype.match would.
Capture groups and named groups
Parentheses capture what they match: in (\d{4})-(\d{2}), group 1 is the year and group 2 the month. Named groups make patterns self-documenting: (?<year>\d{4})-(?<month>\d{2}), read in code as match.groups.year.
(?:…)groups without capturing, for alternation or quantifiers:(?:https?|ftp)://.\1or\k<name>refers back to an earlier group inside the pattern:\b(\w+)\s+\1\bfinds doubled words.- A group that didn't take part in a match is shown as (no match), which is different from an empty match.
Match details lists every group of every match (the first 500), with names in the column headers.
Replacing with $1 and named references
In Replace with, these sequences insert parts of the match:
| Write | Inserts |
|---|---|
$1, $2 … | the numbered group |
$<name> | a named group |
$& | the whole match |
$' | the text after the match (a dollar sign followed by a backtick gives the text before it) |
$$ | a literal dollar sign |
Example: pattern (\w+)@(\S+) and replacement $2/$1 turn ada@example.com into example.com/ada. Without the g flag only the first match is replaced, which the preview points out. For bulk edits on plain text without writing a pattern, use find and replace text.
Flavour differences: JavaScript, PCRE, Python
This tester uses your browser's JavaScript engine, so results match what RegExp does in Node.js and browsers. Most syntax is shared with PCRE (PHP, nginx, Apache) and Python's re, but not all:
- Named groups: JavaScript and .NET write
(?<name>…); Python writes(?P<name>…); PCRE accepts both. - Lookbehind: JavaScript allows any length; Python and most PCRE versions need a fixed length.
- Inline flags: PCRE and Python accept
(?i)at the start of a pattern. JavaScript only has the scoped form(?i:…), added in ES2025 and missing from older browsers, so use the flag checkboxes instead. - Possessive quantifiers and atomic groups (
a++,(?>…)) exist in PCRE, not in JavaScript. - `\A`, `\Z`, `\h` are PCRE/Python; use
^,$(withoutm) and[ \t]in JavaScript.
For .htaccess patterns, which are PCRE, the .htaccess tester runs rules against a URL.
Quick reference
| Token | Matches |
|---|---|
. | any character except a line break (any at all with s) |
\d \w \s | digit, word character ([A-Za-z0-9_]), whitespace |
\D \W \S | the opposites |
\b | a word boundary |
[abc] [^abc] [a-z] | one of, none of, a range |
* + ? | 0 or more, 1 or more, 0 or 1 |
{3} {2,5} {2,} | exactly, between, at least |
*? +? | lazy: as few as possible |
^ $ | start and end (of each line with m) |
(?=x) (?!x) | followed by / not followed by x |
(?<=x) (?<!x) | preceded by / not preceded by x |
\p{L} | any letter in any script (needs u) |
Alternation uses a vertical bar: cat|dog matches either word, and gr(a|e)y matches gray and grey.
Is my text private?
This tool runs entirely in your browser. Your text is not uploaded to our servers.
