← All built-ins / preg_match()
preg_match()
preg_match(...$args): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $pattern | string | /…/ pattern with optional flags i, s, m |
| $subject | string | string to search |
| $matches | array | out-parameter: filled with the match (index 0) and capture groups (1..n)optional |
Return value
1 and fills $matches on success; false on no match or invalid pattern.
Example
$n = preg_match("/(\w+)@(\w+)/", "mail me: ada@holy.php");
echo $n, "
";
$m = null;
preg_match("/(\w+)@(\w+)/", "mail me: ada@holy.php", $m);
echo $m[1], " ", $m[2], "
";1 ada holy