I am trying to split a string like :"ThisIsA STRING"
I want it splitted like this :"This Is A STRING"
My current regex gives me the following result :"This Is A S T R I N G"
$filname_desc = preg_replace('/([a-z0-9])?([A-Z])/','$1 $2',$filname_desc);
Is it possible to modify the regex to only split if the following character is a lowercase?
php> $str = "ThisIsA STRING"
php> echo preg_replace('/([a-z])([A-Z])/','$1 $2', $str)
This Is A STRING
Try
$filname_desc = preg_replace('/([a-z0-9]+)?([A-Z]+)/','$1 $2',$filname_desc);
Use a Lookahead:
$filname_desc = preg_replace('/([a-z0-9])(?=[A-Z])/','$1 ',$filname_desc);
[a-z0-9]
matches only if it is followed by [A-Z]
.
Remove the '?' symbol between the brackets.