ToolsHub4u

Test a regular expression against sample text

Enter a pattern without slashes, choose flags and paste the text to search. Every match is listed with its index and capture groups.

  • Live matching
  • Capture groups
  • JavaScript syntax
Ready Developer & Utility
1Enter
2Adjust
3Copy result

Regex Tester

1

Pattern and sample text

Written without the surrounding slashes. Use double backslashes in this box only if your source code needs them.

Flags

Global matching is always used to find every match. The other flags are applied as selected.

No data yet Live
2

Matches

8 matches found.

Matches

8

Highlighted matches
  • Pattern compiledThe browser accepted the expression with the selected flags.
  • Matches foundPositions count from zero at the start of the text.
  • Empty matches advance by oneA zero-length match is recorded and the search advances one character, so the loop always ends.
Match positions and capture groups
#IndexMatchGroups
10"Ada"—
24"Lovelace"—
332"Analytical"—
443"Engine"—
551"Charles"—
659"Babbage"—
780"Grace"—
886"Hopper"—
Pattern length
15
Flags used
g
Text characters
113
Matches
8

This uses JavaScript regular expression syntax, not PCRE, Python or Java syntax. Lookbehind, named groups and Unicode property escapes depend on the browser engine. Avoid nested quantifiers on long input: they can take exponential time and freeze the tab.

This page runs a JavaScript regular expression against sample text and lists every match with its position and capture groups. Type the pattern without surrounding slashes, tick the flags you need, and paste or load the text to search. Results update as you type, and an invalid pattern is reported rather than silently ignored.

It uses the browser's own RegExp engine. That is the same engine that will run the expression in a web page, so a pattern that works here will behave the same in Chrome, Firefox or Safari, subject to their support for newer syntax. It is not a PCRE, Python or Java tester, and patterns written for those engines may not compile.

Pattern and flags

The pattern field takes the expression only. Writing /\bword\b/g with the slashes and the flag will be treated as a literal slash, a word boundary, and so on, which is not what most people intend. Enter \bword\b and choose the flags from the checkboxes.

Global matching is always on. The g box is ticked and fixed, because the page is built to find every match; unchecking it could not change the result, so it is disabled rather than left looking adjustable. The other four flags work as selected. i ignores case, m makes ^ and $ match at line boundaries, s lets . match a newline, and u enables Unicode mode, which is required for property escapes such as \p{Emoji} and for correct handling of astral characters.

There is no y (sticky) checkbox and no d (indices) checkbox. If you need those, test in the browser console instead. The pattern is limited to 500 characters, and a longer one is refused with a warning rather than attempted.

Reading the match table

Each row shows a one-based match number, a zero-based index, the matched text and any capture groups. Numbered groups appear in order, and named groups appear as their captured values. The index is a JavaScript string index, so it counts UTF-16 code units: a match after an emoji can have an index two higher than the visible character count suggests.

The matched text is shown in quotes so leading and trailing spaces are visible. A zero-length match is shown as "" in the table. In the highlighted preview it is drawn as a thin amber caret rather than a character, so the text you pasted is not altered by a marker that was never in it.

The page records a zero-length match and then advances one character before searching again. In Unicode mode it advances a whole code point instead, so an emoji is not split and the same position cannot match twice. Without that rule, an empty pattern with u on could repeat the position inside an emoji until the list cap. That was a real bug, and it now returns 4 positions for a😀b instead of 1,000.

The list stops at 1,000 matches. If a 1,001st match exists, the status says the list was capped and the count carries a plus sign. Exactly 1,000 matches is reported as complete, because nothing was cut. The table shows the first 50 rows and says so; all matches are in the copied list and the download.

A worked example

The default pattern \b[A-Z][a-z]+\b against the two-sentence sample found 8 capitalised words: Ada, Lovelace, Analytical, Engine, Charles, Babbage, Grace and Hopper. The positions ran from 0 to 86, and the pattern length was 15.

Five patterns and their results
PatternFlagsResult
\b[A-Z][a-z]+\bg8 matches
(?<year>\d{4})-(?<month>\d{2})g2 matches, year and month captured
\p{Emoji}gu2 matches, both emoji
^gm3 zero-length matches
a over 1,001 charactersg1,000 matches, list capped

The named-group run found 2026-11 and 2025-01, with the year and month shown as separate captures. That is the quickest way to check that a date pattern groups the parts you expect before using it in code.

The Unicode run matched the two emoji in ok 👍 done 🚀 only when u was ticked. Without it, a property escape is a syntax error. The zero-length run produced three empty matches, one at the start of each line, and the page's advance rule kept the loop finite. A run of exactly 1,000 a characters reported 1,000 matches without a cap; adding one more character produced the capped result in the table.

An empty match is still a matchA zero-length result is not a bug. It means the pattern can succeed without consuming a character, which is how anchors and some lookarounds behave.

Invalid patterns and slow patterns

An unclosed group, an unmatched bracket, a trailing backslash or a quantifier with nothing to repeat produces a syntax error with the engine's message. The page names the problem and does not attempt a repair. A group name that is not a valid identifier is another common cause.

Catastrophic backtracking is a real risk with nested quantifiers on long input. A pattern such as (a+)+$ against a long run of a followed by one other character can take exponential time and freeze the tab. The page warns about this in its note, but it cannot detect every dangerous pattern. If the page stops responding, close the tab; there is no timeout.

The 500-character pattern cap and the 1,000-match list cap are the only hard limits. The text itself has no stated length limit, though a very large paste will be slower to scan. Uploaded files are read as text and capped at 5 MB by the shared file reader.

JavaScript syntax, not PCRE

Lookbehind, named groups and Unicode property escapes are supported in current browsers, and the tests confirmed all three. Older engines may reject lookbehind or named groups. If the pattern must run in an old browser or a server-side language, test it in the target environment rather than assuming this result carries over.

PCRE features such as \A, \z, possessive quantifiers and recursion are not part of JavaScript. Python's (?P<name>.) group syntax is also different from JavaScript's (?<name>.). A pattern copied from another language often needs rewriting, not just flag changes.

For a broader syntax test or an explanation of each token, a dedicated multi-engine tester is the better tool. This page is for confirming that a JavaScript pattern matches the text you expect, with the exact engine your users will run. The Markdown to HTML converter and the JSON formatter are unrelated but often used in the same documentation workflow.

Questions

Common questions

Short answers about this tool and its limits.

Do I include the slashes around the pattern?

No. Enter only the expression, such as \bword\b, and choose flags with the checkboxes. Slashes typed into the field are treated as literal characters to match.

Why is the g box ticked and disabled?

Global matching is always applied so the page can list every match. The box is fixed on rather than left clickable, because turning it off would not change the result. The other flags, including i, m, s and u, work as selected.

Does it support named groups and lookbehind?

Yes in current browsers. The tests confirmed named captures and a lookbehind. Support depends on the browser engine, so test in your oldest target browser if that matters.

Why are only 1,000 matches listed?

The list is capped to keep the page responsive. Exactly 1,000 matches is reported as complete; a 1,001st match triggers the cap and a plus sign. The table shows the first 50 rows, and the copy and download contain all 1,000.

Why is my pattern rejected as too long?

Patterns are limited to 500 characters. A longer expression is refused rather than run. Split the work into simpler patterns or test it in the browser console.

Can a pattern freeze the page?

Yes. Nested quantifiers on long input can cause catastrophic backtracking, and there is no timeout. Avoid patterns such as (a+)+$ on untrusted text, and close the tab if it stops responding.

Is this PCRE or Python syntax?

Neither. It is JavaScript. Features such as \A, possessive quantifiers and Python's (?P<name>) groups do not work here. Rewrite the pattern for JavaScript rather than only changing flags.

Is my test text uploaded?

No. Matching runs in the browser with no account or server copy. Uploaded files are read locally and capped at 5 MB. Copy or download the match list before leaving the page.