JavaScript regex guide: flags, capture groups and match positions
Use this tester to inspect JavaScript regular-expression matches and captures before applying a pattern in your code. It uses the browser’s native engine, not PCRE, Python or a server-side regex engine. Syntax and supported features can differ between languages and browsers. This page does not perform replacement.
How to enter and test a pattern
Enter the pattern itself without slash delimiters, paste test text, select flags and click Test regex. For example, use \d+ with g on the text Order 12, item 345 to find 12 and 345. Empty test text is allowed. To intentionally match an empty pattern, enter (?:). Edits clear stale results; Clear removes the pattern, text and results while preserving flag choices.
What do g, i, m, s and u change?
g finds successive non-overlapping matches; without it, only the first is returned. i ignores case according to JavaScript rules. m changes ^ and $ to work at line boundaries. s allows . to match line breaks. u enables Unicode-aware syntax and code-point handling, but does not make every character class match every writing system. These flags do not make JavaScript syntax interchangeable with another regex engine.
Capture groups, empty strings and index ranges
Each card shows the full match and a half-open range [start, end): start is included, end is excluded. Indices count UTF-16 code units, not displayed characters; an emoji may use two units. Capturing groups start at #1 and named groups also show their names. An unmatched optional group is different from a group that matched an empty string. Zero-length matches are valid and appear as position markers.
Why can a test stop or show only part of the matches?
Patterns run in a separate Worker with a 2-second deadline, including worker startup. Stop terminates the current test. Pattern and text limits are 4,096 and 100,000 UTF-16 code units. Display stops at 500 matches, 5,000 capture entries or 200,000 units of returned match/capture text. Large captures can reach the limit sooner. When limited, the count is displayed matches rather than a complete total. A timeout or syntax error does not mean there were no matches.
Copying matches and reading the preview
Highlighting and capture cards come from one matching pass. Copy joins the recorded full matches with a line feed; it does not include capture labels or trim whitespace. A match may itself contain line breaks, and empty matches produce blank entries. The preview’s zero-length marker is visual only. Text is displayed as text rather than executed as HTML.
Browser requirements and local processing
The site must be able to load the Worker script; a blocked or missing Worker produces an error instead of running the pattern on the main page. The test function does not submit patterns or text to a server or save them in browser storage. Shared website resources and scripts still load, so this is not an offline or isolated environment guarantee. Browser textareas can normalize line endings.