preg_match()

Performs a regular expression match. Returns 1 if a match is found, 0 if not, or false on error.

Syntax

php
preg_match(string $pattern, string $subject, array &$matches = []): int

Example

php
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
  echo "Valid date format";
}

preg_match('/Hello (\w+)/', "Hello Alice", $m);
echo $m[1]; // Alice