What are some potential pitfalls when using regular expressions in PHP to detect duplicate characters?

One potential pitfall when using regular expressions in PHP to detect duplicate characters is that the regex pattern may not handle all edge cases, such as special characters or multi-byte characters. To solve this issue, it is recommended to use the Unicode modifier 'u' in the regex pattern to ensure proper handling of multi-byte characters.

$string = "hello";
if (preg_match('/(.)\1/u', $string)) {
    echo "Duplicate characters found";
} else {
    echo "No duplicate characters found";
}