How to test a JavaScript regex against your own text
- Type the pattern into Regular expression without the surrounding slashes. The field already shows them, so
\d+is enough;/\d+/would look for literal slashes. - Choose flags. Only
gis on by default. Leave it on if you want every match, because without it the tester stops after the first one. - Paste your sample into Test text. Results update as you type, and the Test button below the field re-runs the pattern straight away.
- Read the result panel. The counter shows how many matches were found. The preview highlights them in place, and the table lists each whole match with its capture groups underneath.
- To try a substitution, switch the mode toggle at the top of the form from Test to Replace and type a replacement string. The rewritten text appears in the replacement preview, and your original input is left unchanged.
- Press Copy report to copy a plain-text summary that you can paste into a code review, ticket or chat.
Example patterns and the reports they produce
Named groups are labelled in the report, so you can check that each part of a pattern captures what you expect. Pattern (?<year>\d{4})-(?<month>\d{2}) with flag g on the text Due 2026-10 and 2027-01:
2 matches
#1: 2026-10 [4–11]
group 1 <year>: 2026 [4–8]
group 2 <month>: 10 [9–11]
#2: 2027-01 [16–23]
group 1 <year>: 2027 [16–20]
group 2 <month>: 01 [21–23]
An optional group that does not take part in a match is marked as unmatched. It is not shown as an empty string. Pattern colou?r(s)? with flags gi on Color, colours:
2 matches
#1: Color [0–5]
group 1: — unmatched
#2: colours [7–14]
group 1: s [13–14]
Flags change the result in ways that are easy to miss:
| Pattern | Flags | Text | Matches |
|---|---|---|---|
^\w+ |
g |
one two / three four (two lines) |
one |
^\w+ |
gm |
same two lines | one, three |
\p{Lu} |
gu |
Łódź and Zürich |
Ł, Z |
\p{Lu} |
g |
Łódź and Zürich |
none |
Without u, \p{Lu} does not raise an error. It silently matches the literal text p{Lu} instead, so it finds nothing in normal prose. Turn on u whenever you use \p{…} escapes or work with emoji.
Rewriting text in Replace mode
Replace mode uses the same rules as JavaScript's String.prototype.replace. With pattern (\d{4})-(\d{2})-(\d{2}), flag g and the replacement $3.$2.$1, the text 2026-10-22, 2027-01-05 becomes 22.10.2026, 05.01.2027. Turn g off and only the first date is rewritten: 22.10.2026, 2027-01-05. Before you paste the replacement into code, use the preview to check that every occurrence changed.
When the pattern works and you want to apply it to a longer document, continue in Find and Replace with its regular expression option turned on. It always replaces every match and ignores case unless you turn on Match case. The m, s and u flags are not available there, so a pattern that depends on them will behave differently.
Where this tester differs from PCRE, Python and server-side engines
The tester uses your browser's JavaScript RegExp engine. A pattern that passes here should behave the same way in JavaScript and TypeScript code (in browsers or Node.js). Other languages may handle it differently:
- Inline modifiers: PCRE and Python accept
(?i)at the start of a pattern. JavaScript rejects it, so use theiflag instead. Newer browsers also accept the scoped form(?i:…), but older engines report it as an invalid group. - Possessive quantifiers and atomic groups:
a++and(?>…)from PCRE are syntax errors in JavaScript. - RE2 (used by Go and some databases): lookarounds and backreferences that pass here are rejected by RE2.
- Size limits: the pattern can be up to 500 characters and the test text up to 100,000 characters. Matching stops after 500 matches, only the first 50 capture groups of each match are listed, and the table shows at most 200 rows (whole matches and groups combined). For large data sets, test a representative sample.
Patterns where a repeated group already contains +, * or {n,} are refused before they run, for example (a+)+ or (\w+\s?)*. Replace the repeated group with a character class: [\w\s]+ covers the same run of words and spaces and runs without the warning. The full JavaScript syntax reference is on MDN: Regular expressions.