How can special characters, such as accented letters, be handled when using regular expressions to search for words in PHP?

Special characters, such as accented letters, can be handled in regular expressions in PHP by using the Unicode character properties. By using the \p{L} property, we can match any Unicode letter, including accented letters. This allows us to search for words with accented characters in a string using regular expressions.

$string = "Café au lait";
$searchTerm = "café";

if (preg_match("/\b" . preg_quote($searchTerm, '/') . "\b/ui", $string)) {
    echo "Match found!";
} else {
    echo "No match found.";
}