我这里有一些代码:
$testString = "text23hello54stack90overflow34test";
$testArray = preg_split("/[0-9]{2}/Uim", $testString);
echo "<pre>".print_r($testArray)."</pre>";
执行这些命令后,我有一个包含以下内容的数组:
{text, hello, stack, overflow, test}
我想修改它,所以我得到:
{text, 23hello, 54stack, 90overflow, 34test}
我怎样才能实现这个目标?
最佳答案
怎么样:
$testString = "text23hello54stack90overflow34test";
$testArray = preg_split("/(?=[0-9]{2})/Uim", $testString);
echo print_r($testArray);
输出:
Array
(
[0] => text
[1] => 23hello
[2] => 54stack
[3] => 90overflow
[4] => 34test
)
关于php - 如何通过正则表达式分割字符串并在输出中保留模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12779596/