Regex tester
Test an ECMAScript regular expression with new RegExp(pattern, flags).
Docify's regex tester builds new RegExp(pattern, flags) in your browser and reads matches with exec. The pattern box is the constructor string, not a /…/ literal — slashes are ordinary characters. Offered flags are gimsuy (no d or v). Without g, only the first match is returned. Test is a button, not as-you-type. There is no replace. Empty patterns are rejected. This is not PCRE, Python, or POSIX. Nothing is uploaded.
Patternnew RegExp("", "g")
Test string
Matches
Match list will appear here after Test...
How it works
- Test is a button, not as-you-type. Load sample fills the pattern, flags, and string only. Copy writes
index-end: matchlines. Nothing is uploaded. - The engine is
new RegExp(pattern, flags)thenexec. Withg, exec is repeated until it returns null, up to 1000 matches. Withoutg, only the first match is kept.yis sticky atlastIndex0 for that first exec. - An empty pattern is rejected. A constructor
SyntaxErroris shown as the first line of the engine message. Capture groups arematch[1]onward; named groups arematch.groups. - This is not PCRE, Python, or POSIX, not a replace tool, and not a regex linter. The
dandvflags are not offered.
FAQ
- Does this tester upload my pattern or text?
- No. Test and copy run in your browser with new RegExp(pattern, flags) and RegExp.prototype.exec. The page does not send the pattern or the string to a server.
- Which regular-expression dialect is this?
- ECMAScript only — the same engine as a JavaScript literal /pattern/flags, built with the RegExp constructor so you type the pattern without delimiters. A slash in the pattern does not need escaping. This is not PCRE, Python re, POSIX BRE/ERE, or Java Pattern. Features such as lookbehind or named groups work only if this browser already implements them.
- What do the g, i, m, s, u, and y flags do?
- They are the ECMAScript flags passed as the second argument to new RegExp. g (global) collects every match via repeated exec; without g, only the first match is returned. i is ignoreCase. m makes ^ and $ match line boundaries. s (dotAll) lets . match LF/CR. u treats the pattern as Unicode code points. y (sticky) matches only at lastIndex, which this page leaves at 0 for the first exec. The d (indices) and v (unicodeSets) flags are not offered.
- Does Test replace text or run as I type?
- No. Test is a button. There is no replace, replaceAll, or $1 substitution. An empty pattern is rejected. A SyntaxError from new RegExp is shown as the first line of the engine message. Capture groups are exec indexes 1+; named groups come from match.groups. Results stop at 1000 matches.
Related
- JavaScript RegExp vs PCRE
- Sibling tools: Text diff and JSON formatter