I need a regex to count characters in a string which need 2 keystrokes to create the character. I started out quite simple, just counting uppercase characters:
preg_match_all('/[A-Z]/', $string, $matches);
Now I also want to find circumflexed characters: â ê î û ô
Just adding these in the regex doesn’t seem to work, at least I receive some weird results:
$string = 'Têst';
echo preg_match_all('/[A-Z]/', $string, $matches);
will echo “1”, which is fine.
$string = 'Têst';
echo preg_match_all('/[A-Zê]/', $string, $treffer);
will echo “3”, which is weird.
You have to use the
umodifier, otherwise “ê” is considered as having 2 chars (2 bytes):Demo @ IDEOne.com.