I have two Strings:
C:\Users\Bob\My Documents
/Users/Bob/Documents
I have managed to conjure this regex:
preg_split('/(?<=[\/\\\])(?![\/\\\])/', $string)
that will return
Array
(
[0] => C:\
[1] => Users\
[2] => Bob\
[3] => My Documents
)
Array
(
[0] => /
[1] => Users/
[2] => Bob/
[3] => Documents
)
However, I am looking for
Array
(
[0] => C:\
[1] => Users
[2] => Bob
[3] => My Documents
)
Array
(
[0] => /
[1] => Users
[2] => Bob
[3] => Documents
)
ie Trailing slashes not present in corrected arrays
Why not just check for “/” or “\” and then use
explodewith the appropriate delimiter?(Updated with a slightly tidier version)