What are the potential pitfalls of using preg_match_all to search for specific patterns in a string?

One potential pitfall of using preg_match_all to search for specific patterns in a string is that it can return a large amount of data, which may impact performance if not handled efficiently. To mitigate this issue, it's important to carefully analyze the patterns being searched for and optimize the regular expression to only capture the necessary data.

// Example of optimizing preg_match_all by using a more specific regular expression pattern
$string = "Hello, my email is john.doe@example.com and my phone number is 123-456-7890.";
$pattern = '/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b|\b\d{3}-\d{3}-\d{4}\b/';
preg_match_all($pattern, $string, $matches);

print_r($matches[0]);