Skip to content
AgileLogics

Regex Tester

Runs a JavaScript regular expression against your test text and lists every match with its position and captured groups.

How it works

Paste the text to search in the input panel, enter a pattern (either bare, like \d+, or as a literal, like /\d+/gi) in the second panel, and click Test.

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

  1. Paste the text you want to search into the Test string box.
  2. Type the pattern into the second box, either bare (\d+) or as a literal with flags (/\d+/i).
  3. 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 foo only 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 \s makes an edge space easier to see.
  • $ and . are special. Searching for a price with $5 finds nothing, because $ means "end of input". Escape it: \$\d.
  • ^ without m only matches once. Against two lines that both start with "line", ^line gives one match and /^line/m gives 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. Use a+ 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

Frequently asked questions

Which regex flavour does the tester use?
JavaScript. The pattern is compiled with the browser's own RegExp engine, so it behaves exactly as it would in JavaScript code running in that browser. Syntax from other flavours, such as PCRE's possessive quantifiers (a++) or atomic groups, is reported as an invalid regular expression.
How do I add flags like i or m?
Write the pattern as a literal with slashes, for example /cat/i or /^line/m. A bare pattern like cat gets no flags apart from g. The tester accepts any flag your browser supports, including d, i, m, s, u, v and y.
Why does it always find every match, even without the g flag?
The tester adds the g (global) flag automatically so it can list all matches in the text, not only the first one. If your code calls match() or exec() without g, it will only see the first match from the list.
Why is a capture group shown as null?
The group is optional and didn't take part in that match. For /a(b)?1/ tested against a1, the match is "a1" and the group list is [null], which is how JSON shows JavaScript's undefined.
Is my test text sent to a server?
No. The pattern runs in JavaScript on this page, so the text you paste stays in your browser.