What are some potential pitfalls when using regular expressions in PHP to extract specific patterns from strings?

One potential pitfall when using regular expressions in PHP to extract specific patterns from strings is not properly escaping special characters. This can lead to unexpected results or errors in the regex matching. To solve this issue, it is important to use the preg_quote() function to escape any special characters in the pattern before using it in the regular expression.

$pattern = '/[a-z]+/';
$escaped_pattern = preg_quote($pattern, '/');
$string = 'abc123';

if (preg_match($escaped_pattern, $string, $matches)) {
    echo 'Match found: ' . $matches[0];
} else {
    echo 'No match found';
}