问题
$str="Hello MotoBell RingsKing Speech";
I need explode this string by uppercase letter if lowercase letter exists before it.
like this:
$splitted=array(
0=>"Hello Moto",
1=>"Bell Rings",
2=>"King Speech"
);
any ideas?
I try use that reg_ex, but not working:
$pieces = preg_split('/(?=[A-ZА-Я])/u', $str, -1, PREG_SPLIT_NO_EMPTY);
回答1:
var_dump(preg_split('/(?<=[a-z])(?=[A-Z])/', 'Hello MotoBell RingsKing Speech'))
// array(3) {
// [0]=>
// string(10) "Hello Moto"
// [1]=>
// string(10) "Bell Rings"
// [2]=>
// string(11) "King Speech"
// }
来源:https://stackoverflow.com/questions/24951067/php-explode-string-with-uppercase-if-lowercase-letter-exists-before-it-without-s