Gavin Kistner wrote:
> On Oct 2, 2005, at 1:06 PM, Alex Fenton wrote:
> > I'm trying to split a path (like an URL, but not one) into bits on
> > the '/' character.
> > Problem is, I want to be able to be able to escape '/' in the names
> > of bits by doubling
> > the character to '//' eg
> >
> > 'foo/bar // baz/qux'
> > => ["foo", "bar / baz", "qux"]
>
> Lookbehind is what you want; until we get it in core ruby, I've
> provided an example of another way to get the above. I've used commas
> instead of / just to help make the regexp easier to understand -
> substitute with "\/" as appropriate:
>
> str = 'foo,bar ,, baz,qux,,,jorb,jing,,,,blat'
> out = []
> str.scan( /(.+?[^,],{2}*)(?:,(?!,)|$)/ ){ |a,b|
>      out << a.gsub( ',,', ',' )
> }
> p out
> #=> ["foo", "bar , baz", "qux,", "jorb", "jing,,blat"]

str = 'foo,bar ,, baz,qux,,,jorb,jing,,,,blat'
p str.scan( /(.+?[^,],{2}*)(?:,(?!,)|$)/ ).map{|x|
  x.first.gsub( /,,/, "," ) }