我有两个字符串:
C:\Users\Bob\My Documents
/Users/Bob/Documents
我设法变出这个正则表达式:
preg_split('/(?<=[\/\\\])(?![\/\\\])/', $string)
那将返回
Array
(
[0] => C:\
[1] => Users\
[2] => Bob\
[3] => My Documents
)
Array
(
[0] => /
[1] => Users/
[2] => Bob/
[3] => Documents
)
然而,我正在寻找
Array
(
[0] => C:\
[1] => Users
[2] => Bob
[3] => My Documents
)
Array
(
[0] => /
[1] => Users
[2] => Bob
[3] => Documents
)
即修正后的数组中不存在尾部斜杠