Regex Tester & Explainer

Test regular expressions live with highlighted match groups and a plain-English explanation of each token. Supports PHP (PCRE2), JavaScript, and Python flavours.

/ /

What is a Regex Tester?

A regular expression (regex) tester lets you write and test patterns against sample text in real time, with match highlighting and group capture details. Regular expressions are sequences of characters that define a search pattern - used in every programming language for input validation, string parsing, data extraction, and find-and-replace operations. This online regex tester supports JavaScript, PHP (PCRE2), and Python flavours with a plain-English explanation of every token, so you can understand what each part of your pattern does without memorising the full regex syntax.

How regex flags work

Flags modify how a pattern matches. The most common are: g (global - find all matches, not just the first), i (case-insensitive), m (multiline - ^ and $ match line starts/ends, not just string start/end), and s (dotAll - . matches newlines too). In PHP you wrap the pattern in delimiters: /pattern/flags, e.g. /hello/i. In JavaScript, flags follow the closing slash.

Frequently Asked Questions

What is the difference between PCRE and JavaScript regex?

PCRE2 (used by PHP) is more feature-rich - it supports named backreferences, atomic groups, possessive quantifiers, and recursive patterns. JavaScript regex is less powerful but sufficient for most use cases. A key practical difference: JavaScript doesn't support lookbehind with variable length in older engines, and uses RegExp objects where PHP uses preg_match().

How do I match a literal dot, parenthesis, or other special character?

Escape it with a backslash: \. matches a literal dot (unescaped, . matches any character). Similarly, \(, \), \[, \{, \+, \*, \?, \^, \$, and \\ are all escaped special characters.

How do I validate an email address with regex?

Simple email validation: /^[^\s@@]+@@[^\s@@]+\.[^\s@@]+$/. For production use, rely on your language's built-in validation (PHP's filter_var($email, FILTER_VALIDATE_EMAIL), or Laravel's Rule::email()) rather than a handwritten regex - RFC 5321 allows many characters that simple patterns miss.

How do I use regex in PHP and Laravel?

preg_match('/pattern/', $subject, $matches) returns 1 on match and populates $matches. preg_match_all() finds all matches. preg_replace('/old/', 'new', $string) replaces matches. In Laravel validation rules, use Rule::regex('/^[A-Z]+$/') or the string shorthand 'regex:/^[A-Z]+$/'.

Related tools