What are the potential pitfalls of using preg_match in PHP for parsing regular expressions?

Using preg_match in PHP for parsing regular expressions can lead to potential pitfalls such as inefficient performance for complex patterns, difficulty in maintaining and debugging complicated regex patterns, and vulnerability to regex injection attacks if user input is directly used in the regex pattern. To mitigate these risks, it is recommended to thoroughly test regex patterns, sanitize user input before using it in regex patterns, and consider using simpler regex functions like preg_match_all or preg_replace when appropriate.

// Example of using preg_match_all instead of preg_match to parse regular expressions
$string = "Hello, my email is test@example.com and my phone number is 123-456-7890.";
$pattern = '/\b(\w+@\w+\.\w+)\b|\b(\d{3}-\d{3}-\d{4})\b/';

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

print_r($matches);