Martin Martin - 5 months ago 34
PHP Question

Fastest way to find first uppercase character in a string

Suppose you have this string:


What is the fastest way to find where the first upper case character is? (
in this example)

I am worried about performance as some words are quite long.


Easiest would be to use preg_match (if there is only 1 match) or preg_match_all (if you want all the matches)

preg_match_all('/[A-Z]/', $str, $matches, PREG_OFFSET_CAPTURE);

Not sure if it is the fastest..