What potential issues or limitations should be considered when using preg_match_all() to extract specific patterns from a string?

One potential issue when using preg_match_all() is that it may return an empty array if no matches are found. To handle this, you can check if the result is empty and handle it accordingly in your code.

// Example code snippet to handle empty result from preg_match_all()

$string = "Hello, World!";
$pattern = "/[0-9]+/";

$result = preg_match_all($pattern, $string, $matches);

if (empty($matches[0])) {
    echo "No matches found.";
} else {
    // Process the matches
    foreach ($matches[0] as $match) {
        echo $match . "\n";
    }
}