What are common pitfalls when using the preg_match function in PHP?

Common pitfalls when using the preg_match function in PHP include not properly escaping special characters in the regular expression, not handling errors or false positives, and not using the correct flags for case sensitivity or multiline matching. To avoid these issues, make sure to carefully construct your regular expression, handle potential errors or unexpected results, and use the appropriate flags for your specific use case.

// Example of using preg_match with proper escaping and error handling

$string = "Hello, world!";
$pattern = "/Hello, world!/";
if (preg_match($pattern, $string)) {
    echo "Match found!";
} else {
    echo "No match found.";
}