Regex Tester
Test a JavaScript regular expression against sample text: every match, its position, numbered and named groups, and a live replace.
Free · No sign-up · Your inputs stay in your browser
Input
Test a JavaScript regular expression
/(?<user>[\w.+-]+)@(?<domain>[\w-]+\.[\w.]+)/g
2 matches
#1 at 9: [email protected]
- $1: hello
- $2: gohacks.dev
- user: hello
- domain: gohacks.dev
#2 at 30: [email protected]
- $1: ops+alerts
- $2: example.co.uk
- user: ops+alerts
- domain: example.co.uk
After replace
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
JavaScript flavor
This is the ECMAScript engine your browser and Node.js use. PHP's preg_* functions use PCRE2, which agrees on most everyday syntax but differs at the edges: PCRE supports possessive quantifiers and recursion, and the delimiters and flags are written differently (/pattern/i in a PHP string).
The flags
g finds every match instead of the first. m makes ^ and $ match at line breaks. s lets . match a newline. u treats the pattern as Unicode code points, and is required for \p{...} property escapes.
The default example
The pattern filled in by default captures the user and domain of each email address with named groups. It is a teaching example, not a validator: real address validation is better left to filter_var($email, FILTER_VALIDATE_EMAIL) or a confirmation email.