I need a regular expression to check a string for uppercase letters. Where It finds a uppercase It needs to add white space before it. I write some code for this, but the problem is that it only works if there is only one uppercase letter in the string. But I need to work with any number of uppercase letter exists in the string. I pasted my code below:
$regEx = preg_match('*[A-Z]*', $str, $matches, PREG_OFFSET_CAPTURE);
if(!empty($regEx)) {
$str = substr_replace($str,' ', $matches[0][1], 0);
}
preg_replace()sounds a more suitable candidate to achieve this…CodePad.