Based on the previous question

How to correctly replace explode in my case?

How to make a variant with // ?

It works incorrectly:

 $str = 'a/b/c/d/e//f/g/h//i'; $arr = preg_split('~(?<!/)/~',$str); 

The answer should be such

 a b c d e//f g h//i 

A little thought, I wrote this code:

 $str = 'a/b/c/d/e//f/g/h//i'; $arr = preg_split('/(?<!\/)\/(?!\/)/',$str); 

Answer:

 Array ( [0] => a [1] => b [2] => c [3] => d [4] => e//f [5] => g [6] => h//i ) 

At first glance, it works correctly, but if there are a lot of //// symbols, then there are no:

 $str = 'a/b/c/d/e////f/g/h//i'; $arr = preg_split('/(?<!\/)\/(?!\/)/',$str); 

The answer should be:

 Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => // [6] => f [7] => g [8] => h//i ) 

How to fix? @Deonis

  • Something like: / (? <! \ /) \ / (?! \ / (?: \ / \ /) *)) / It is not clear how to divide: e /// fe ///// f - ReinRaus
  • For your options, [you can try this] [1]: $ arr = preg_split ('# (? <! [Az] \ /) \ / (? = [Az] | \ / {3}) #', $ str ); But I agree with @ReinRaus - what to do if there are an odd number of slashes in a row or there will be a couple of them? [1]: ideone.com/GLUR4J - Deonis

0