What are common pitfalls when using preg_match in PHP scripts?

One common pitfall when using preg_match in PHP scripts is not properly escaping special characters in the regular expression pattern. This can lead to unexpected results or errors when trying to match certain strings. To avoid this issue, it's important to use the preg_quote function to escape special characters before using them in the pattern.

// Incorrect usage without escaping special characters
$pattern = '/[a-z]+/';

// Corrected usage with escaping special characters
$pattern = '/'. preg_quote('[a-z]+') .'/';