On Thursday 30 September 2004 23:29, Simon Strandgaard wrote:
> On Thursday 30 September 2004 23:15, Mark Probert wrote:
> > Hi, Rubyists.
> >
> > What is the best way of attacking field split on ';' when the string
> > looks like:
> >
> >   s = 'a;b;c\;;d;'
> >   s.split(/???;/)
> >   => ["a", "b", "c\;", "d"]
> >
> > Or is it best to use s.each_byte and do it by hand?
>
> How about something ala
>
> irb(main):015:0> "aa;bbb\\;;abc;;d\\\\;e;".scan(/(?:\\[^.]|[^;])*;/)
> => ["aa;", "bbb\\;;", "abc;", ";", "d\\\\;", "e;"]


maybe this one is better ?

irb(main):001:0> "aa;bbb\\;;abc;;d\\\\;e;f".scan(/(?:\A|;)((?:\\[^.]|[^;])*)/) 
{ p $1 }
"aa"
"bbb\\;"
"abc"
""
"d\\\\"
"e"
"f"
=> "aa;bbb\\;;abc;;d\\\\;e;f"
irb(main):002:0>

--
Simon Strandgaard