PHP Regex Match Example

Validate and extract text with regular expressions and preg_match(). Edit the code below and press Run to execute it with real PHP in your browser.

Code Editor
Output
Valid email: [email protected]
Extracted price: $19.99

How this regex match example works

preg_match() returns 1 when the pattern matches and stores captured groups in $matches. Patterns are written in single quotes so that \. and \$ reach the regex engine unchanged. For real email validation, filter_var($email, FILTER_VALIDATE_EMAIL) is more reliable than a hand-written pattern.