Regex Tester
Test a regular expression against your text: see every match with its position and capture groups, and preview a replacement.
JavaScript RegExpJavaScript engine · test text up to 1 MB · 1-second time limit
$1…$99 group, $<name> named group,$& whole match, $` before it, $' after it,$$ a literal $.| # | Match | Position | Groups |
|---|
Runs in your browser. Nothing you enter is sent anywhere. How to check
1.How to use
- Choose Match to list matches or Replace to preview a replacement.
- Type the regular expression without slashes and tick its flags. Pasting a literal such as
/abc/giremoves the slashes and sets the flags for you. - Enter the test string. Every match is highlighted, and the list below gives its position and capture groups.
- In Replace mode, enter the replacement and copy the result.
Results appear 250 ms after you stop typing. The engine is named next to every result. Other languages, such as Python, Java, .NET and Go, have their own engines and can give different results for the same pattern.
2.Examples
Extracting dates with named groups
The pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) with g on, againstDeployed 2026-11-30, rolled back 2026-12-01, redeployed 2026-12-03., finds 3 matches. The first is 2026-11-30 at positions 9–19, with the groupsyear = 2026, month = 11 and day = 30. Load example fills in this case.
The effect of m and s
Against the two lines foo and bar, ^\w+ matches only foo. With m, ^ also matches after each line break, so it matches foo and bar. Likewise a.c does not matcha, a line break, c, because . skips line breaks; withs it does.
Reordering a date with a replacement
In Replace mode, the date pattern above with the replacement$<day>/$<month>/$<year> turns the example intoDeployed 30/11/2026, rolled back 01/12/2026, redeployed 03/12/2026.
A pattern that differs between JavaScript and PCRE2
a++ is a possessive quantifier in PCRE2 and PHP: it matches a run ofa and never gives characters back. JavaScript has no possessive quantifiers, so this page reports "Nothing to repeat" and notes that the syntax works in PCRE2.
3.Options explained
Engine
JavaScript uses your browser's own RegExp, so the matches are what JavaScript code gets in this browser. PCRE2, the library behind PHP'spreg_ functions, is coming soon and cannot be selected yet.
Flags
| Flag | Name | Effect |
|---|---|---|
| g | global | Find all matches. Without it, only the first match is shown and replaced. |
| i | ignore case | Case-insensitive matching. |
| m | multiline | ^ and $ also match at line breaks. |
| s | dotAll | . also matches line breaks. |
| u | unicode | Unicode mode: \p{L} property escapes, and an emoji counts as one character. Undefined escapes become errors. |
| v | unicodeSets | Extended Unicode mode with set operations in classes, such as [\p{L}--[a-z]]. Cannot be combined with u. |
| y | sticky | Each match must start exactly where the previous one ended, starting at position 0. |
Replacement syntax
The replacement follows String.prototype.replace. It is text, never code.
| Write | Inserts |
|---|---|
| $1 … $99 | The numbered group. A group that does not exist is an error. |
| $<name> | The named group. |
| $& | The whole match. |
| $` | The text before the match. |
| $' | The text after the match. |
| $$ | A literal $. A $ before any other character is also kept as is. |
4.Limits
- One engine for now: JavaScript. PCRE2 is planned.
- Pattern up to 10,000 characters and test text up to 1 MB. The first 1,000 matches are highlighted and listed; the count includes all of them.
- Matching stops after 1 second. Some patterns take exponential time on certain text, and the limit keeps the page responsive.
- Positions count characters (Unicode code points), start at 0, and the end is exclusive. Lines and columns start at 1.
5.FAQ
Why does my regex work here but not in Python?
Each language has its own engine. For example, Python's re module also accepts(?P<name>…) for named groups, which JavaScript rejects, and does not support\p{L}. Test with the engine your code uses.
How do JavaScript and PCRE2 differ?
PCRE2 has syntax JavaScript lacks: possessive quantifiers (a++), atomic groups ((?>…)), recursion ((?R)), \K, and inline flags such as (?i) at the start of a pattern. In replacements, PCRE2 writes named groups as${name} where JavaScript writes $<name>.
What is catastrophic backtracking?
A pattern such as (a+)+$ can split a run of a between the inner and outer quantifier in an exponential number of ways. When the text ends in a character that does not match, the engine tries them all. Remove the nesting (a+$) or make the alternatives exclusive.
What is the difference between greedy and lazy?
Quantifiers are greedy by default: <.+> on <a><b> matches the whole <a><b>. Adding ? makes them lazy:<.+?> matches <a> and <b> separately.
Can I use named references with PHP's preg_replace?
No. preg_replace accepts only numbered references: $1,\1 and ${1}. Use the group's number instead of its name.
How are Windows line endings handled?
A Windows line break is two characters, \r\n. In JavaScript, withm, ^ and $ treat \r and \neach as a line break, so ^$ also matches the empty position between them. Withouts, . matches neither.
Is my text uploaded?
No. The pattern and text never leave your browser, and they are not stored. Only your options and flags are remembered on this device. The privacy pageshows how to confirm this in your browser's Network tab.