What are common pitfalls when using regex in PHP for string manipulation?

One common pitfall when using regex in PHP for string manipulation is not properly escaping special characters. This can lead to unexpected results or errors in the regex pattern. To solve this, make sure to use the `preg_quote()` function to escape any special characters in the input string before using it in the regex pattern.

$input_string = "Hello (world)!";
$escaped_string = preg_quote($input_string, '/');
$pattern = '/\(\w+\)/'; // Matching parentheses followed by word characters

if (preg_match($pattern, $escaped_string, $matches)) {
    echo "Match found: " . $matches[0];
} else {
    echo "No match found.";
}