ℹ️ About Regex Tester
Regex Tester is an online JavaScript regular expression tester. Type a pattern and some sample text, and it lists every match with its position and capture groups, previews a find-and-replace, and summarises the pattern's structure before you paste it into an application, script, or editor.
Regular expressions are pattern-matching rules used for search, validation, parsing, and text transformation. This page compiles your pattern with the browser's native RegExp constructor, so matching follows the
ECMAScript RegExp specification
and the syntax documented on
MDN Web Docs. Typical uses: checking the shape of form input, pulling fields out of logs or pasted command output, and debugging $1 and $& before a find-and-replace.
Supported inputs
- Pattern: a regular expression body without slashes, in any syntax
new RegExp(pattern, flags)accepts: named groups(?<name>...), lookahead, lookbehind, backreferences. - Flags: four checkboxes,
gglobal (on by default),iignore case,mmultiline anchors,sdot-all. No other flags can be set. - Test string: any text, including multiple lines; the textarea sets no length limit.
- Replacement (optional): a
String.prototype.replacereplacement string, so$1,$<name>,$&,$`,$', and$$all work. Blank skips the replace preview. - Three presets (email, phone, URL) fill pattern, text, flags, and replacement in one click; the page opens with the email preset loaded, which also ticks
i. An empty pattern or test string gives no matches and no error, and the API rejects both with HTTP 400.
Output
- Matches: one entry per match with the matched text, its zero-based start and exclusive end positions, and the numbered capture groups. A group that did not participate is
nullin the API and(empty)on the page.glists every non-overlapping match; without it only the first appears. - Replace result: the test string after
String.prototype.replacewith the same flags. - Pattern analysis: pattern length, the resolved flag string, a capture group count, and yes or no for character classes, quantifiers, and anchors, all from a character scan (see Limitations).
- Error: an invalid pattern yields
Invalid regex pattern: ...with the engine's own message instead of matches, and HTTP 400 from the API. Responses carrymatches,replaceResult,patternAnalysis,flags, anderrorbeside the echoed inputs.
Example
Pattern (\w+)@(\w+\.\w+), flag g, test string [email protected] [email protected], replacement [$1] gives two matches: [email protected] at 0-10 (groups a, test.com) and [email protected] at 11-24 (groups b, example.org). The replace result is [a] [b]; the analysis reports 2 capture groups, quantifiers present, no character classes, no anchors. Also try ^ERROR\s+\[(.+?)\] with m, which captures the bracketed component of every error line.
Limitations
- JavaScript flavour only. PCRE, Python, Java, .NET, and RE2 constructs that JavaScript lacks are rejected:
(?P<name>...), atomic groups(?>...), leading inline flags such as(?i), possessive quantifiers such asa++.\Aand\Zdo compile, but match the literal letters A and Z. - The
u,v,y, anddflags are not exposed, so\p{L}matches the literal textp{L}, characters outside the Basic Multilingual Plane count as two UTF-16 code units, and positions are UTF-16 code unit offsets, not byte or code point offsets. - Capture groups are reported by number only: named groups work in the pattern and in
$<name>replacements, but the names are never shown. - The pattern analysis is a character scan, not a parse. It counts every
(not directly preceded by a backslash, so non-capturing groups, lookarounds, and even a literal(inside[...]inflate the group count, and it reports quantifiers, anchors, or classes as soon as*,+,?,{,^,$, or[...]appears, escaped or negated-class occurrences included. - No execution timeout in the browser, so a pattern that backtracks catastrophically can freeze the tab, the class of issue OWASP calls Regular Expression Denial of Service. Keep production patterns specific and test them against worst-case text.
- Regular expressions are not full parsers; complete validation of email addresses, URLs, HTML, or source code needs a dedicated parser.
- The public API runs the pattern in a Node process killed after 5 seconds, rate limited to 30 requests per minute for anonymous callers.
Browser or server processing
Everything on this page runs in your browser through the compiled regex-tester.logic.js module, so the pattern, test string, and replacement never leave your machine. The public API runs the same module server-side through a Node.js bridge, so V8 compiles the pattern rather than PHP's PCRE library and the results follow the same ECMAScript semantics as the page; only syntax your own browser does not implement yet, such as inline modifier groups (?i:...), can differ. API calls are the one path that sends your pattern and text off your machine.
FAQ
Why does my regex work here but not in Python, PHP, or Java?
This tester uses the JavaScript flavour, which names groups (?<name>...) where Python writes (?P<name>...) and which lacks several constructs those engines provide (see Limitations). Confirm the pattern in the runtime that will actually execute it.
Why does the dot (.) not match newlines?
In JavaScript . matches any character except line terminators unless the s (dot-all) flag is set. Tick s - Dot all and a.b then matches a, newline, b.
How do I test regex flags?
Toggle the four checkboxes next to the pattern; the /pattern/flags preview, the matches, and the replace result all update on every change, so you can compare g on against off, or m on against off, without leaving the page.
Why does the page freeze when I type a pattern?
The tester re-runs the expression on every keystroke with no timeout, so (a+)+$ against a run of a characters ending in b can backtrack for a very long time. Simplify the nested quantifiers, or shorten the test string.
References
API Usage Example:
POST /api/tools/webdev/regex-tester
Content-Type: application/json
{
"pattern": "\\d+",
"testString": "abc123def456",
"flags": {
"global": true,
"ignoreCase": false,
"multiline": false,
"dotAll": false
},
"replacement": "#"
}