What are common pitfalls when using regular expressions in PHP, as seen in the provided code snippet?

One common pitfall when using regular expressions in PHP is not properly escaping special characters. This can lead to unexpected behavior or errors in the regex pattern matching. To solve this issue, it's important to use the preg_quote() function to escape any special characters in the input string before using it in the regular expression pattern.

// Incorrect code snippet
$input = "Hello (World)";
$pattern = "/\($input\)/"; // Incorrect usage of input without escaping special characters

// Corrected code snippet
$input = "Hello (World)";
$escaped_input = preg_quote($input, '/');
$pattern = "/\($escaped_input\)/"; // Escaping special characters in input before using in regex pattern