Matching with preg_match
Test strings against patterns and capture groups.
preg_match() Signature
preg_match($pattern, $subject, &$matches) returns 1 if the pattern matches, 0 if it does not, or false on error.
Simple Match Test
Use preg_match as a boolean test — return value 1 means found.
<?php
$email = "user@example.com";
if (preg_match('/\w+@\w+\.\w+/', $email)) {
echo "Looks like an email";
}All lessons in this course
- Regex Syntax Fundamentals
- Matching with preg_match
- Replacing Text with preg_replace
- Splitting and Practical Patterns