What is a regex tester?
A regex tester runs a regular expression against sample text and shows what it matches, so you can get a pattern right before it goes into code. This one uses JavaScript's built-in RegExp engine and lists every match with its starting position and the contents of each capture group, or the engine's error if the pattern is invalid.
Regular expressions in JavaScript are defined by the ECMAScript language specification, and MDN's regular expressions guide is the most readable reference for the syntax.
How to test a regular expression
- Paste the text you want to search into the Test string box.
- Type the pattern into the second box, either bare (
\d+) or as a literal with flags (/\d+/i). - Click Test. The result lists how many matches were found, then one line per match.
Each result line has the form #1 at index 6: "66". The index is zero-based and counts UTF-16 code units, the same way JavaScript's match.index does, so an emoji such as 👍 takes up two positions. When the pattern has capture groups, their values follow in a list.
Worked example
Test string:
Order 66 shipped on 2026-10-05, invoice 1042.
The pattern \d+ finds every run of digits:
5 match(es) found:
#1 at index 6: "66"
#2 at index 20: "2026"
#3 at index 25: "10"
#4 at index 28: "05"
#5 at index 40: "1042"
To pick out only the date and split it into parts, use groups: /(\d{4})-(\d{2})-(\d{2})/ returns a single match, "2026-10-05", with the groups ["2026","10","05"]. Named groups such as (?<year>\d{4}) work too, but the list shows their values by position without the names.
Bare patterns and flags
A pattern typed without slashes is compiled with no flags other than g. To use flags, wrap the pattern in slashes and put the flags after the closing one. The tester always adds g so that it can list every match.
| Flag | Name | Effect |
|---|---|---|
i |
ignoreCase | /cat/i matches cat, 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 the pattern as Unicode code points and enables \p{...} property escapes |
v |
unicodeSets | A stricter Unicode mode with set operations in classes; can't be combined with u |
y |
sticky | Each match must start exactly where the previous one ended |
d |
hasIndices | Records group start and end positions (the tester's output doesn't display them) |
A flag letter that isn't valid, or u and v together, produces an "Invalid flags" error. The MDN RegExp flags reference covers each one in detail.
Things that commonly trip people up
- Spaces in the pattern count. Leading and trailing spaces are kept, so
fooonly matches "foo" with a space on each side. Only line breaks at the very start or end of the pattern box are ignored, so pressing Enter after typing a pattern doesn't change it. Writing[ ]or\smakes an edge space easier to see. $and.are special. Searching for a price with$5finds nothing, because$means "end of input". Escape it:\$\d.^withoutmonly matches once. Against two lines that both start with "line",^linegives one match and/^line/mgives two.- Empty matches are listed. A pattern that can match nothing, like
a*, reports zero-length matches such as#1 at index 0: ""between the real ones. Usea+if you only want non-empty runs. - Some patterns are extremely slow. Nested quantifiers like
/^(a+)+$/backtrack exponentially when the match fails. Against 26 letter a's followed by a b, that pattern took several seconds to give up in our test, and longer inputs can freeze the tab. Rewrite it as/^a+$/.
JavaScript vs other regex flavours
Most everyday syntax (classes, quantifiers, groups, alternation, lookahead) is shared between JavaScript, PCRE (used by PHP), Python and Java. Lookbehind like (?<=\$)\d+ also works in JavaScript. The differences show up in less common features: JavaScript has no possessive quantifiers (a++) or atomic groups ((?>...)), and both are rejected as invalid here. If your pattern is headed for another language, test it with that language's engine too.
Related tools
- Find and replace: run a regular expression over text and substitute the matches, including
$1-style group references. - Remove Duplicate Lines: once a pattern has pulled values out of a log or list, keep one copy of each.
- JavaScript editor: write the code that uses your finished pattern, with syntax highlighting.
- Code diff: compare text before and after a regex-based edit to check what changed.
Last updated