What are the potential pitfalls of using preg_match() to match patterns in PHP?

Using preg_match() to match patterns in PHP can be inefficient when dealing with complex patterns or large strings, as it can lead to performance issues. Additionally, improper usage of regular expressions can result in unexpected matches or errors. To mitigate these pitfalls, consider using more specific regular expressions and optimizing the pattern matching process.

// Example of using preg_match_all() instead of preg_match() for matching patterns
$string = "Hello, my email is test@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]);