On Oct 2, 2005, at 2:06 PM, Alex Fenton wrote:

> Hi
>
> 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"]
>
> In a perlish regex I could use zero-width assertions either side thus
> string.split(/(?<!\/)\/(?!\/)/)
>
> but there's no lookbehind in Ruby - I wonder if someone could  
> suggest a neat
> ruby alternative.

Don't know if your case is loose enough to allow for a hack like  
this, but maybe it will give you ideas:

irb(main):001:0> "foo/bar // baz/qux".gsub("//", "\0").split("/").map  
{ |e| e.gsub("\0", "/") }
=> ["foo", "bar / baz", "qux"]

If that doesn't work, it's probably time to break out StringScanner...

James Edward Gray II