Skip to content
gohacks.dev
Standard Library

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.

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.

Share

Frequently asked questions

Will a regex that works here work in PHP?
Usually, for everyday patterns. Wrap it in delimiters for preg_match, and test anything using lookbehind, Unicode properties or flags in PHP itself.
Why does my pattern freeze the page?
Nested quantifiers such as (a+)+ can backtrack exponentially on input that almost matches. Rewrite the pattern so each character can be matched in only one way.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools