Martin Martin - 1 year ago 86
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.

Answer Source

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..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download