Are there any potential pitfalls in using preg_match() to search for regex matches in PHP?

When using preg_match() to search for regex matches in PHP, one potential pitfall is not properly handling errors that may occur during the matching process. To solve this issue, it is important to check the return value of preg_match() to ensure it executed successfully before using the results.

$pattern = '/[0-9]+/';
$string = 'abc123xyz';

if (preg_match($pattern, $string, $matches)) {
    // Match found, use $matches array
    echo "Match found: " . $matches[0];
} else {
    // No match found
    echo "No match found";
}