根据大写字母分隔字符串

cevin
  • 7.1k

比如

wordWordWordWord

分隔成数组

word,Word,Word,Word

正则该怎么写

回复
阅读 5k
1 个回答
tabalt
  • 1.3k
✓ 已被采纳

楼上的正则有够复杂,来个简单的,先替换再切割:

<?php
$str = "wordWordWordWord";
$splitChar = ",";
$formatStr = preg_replace("/([A-Z])/", ",\\1", $str);

$wordList = explode($splitChar, $formatStr);
print_r($wordList);
宣传栏