From: Florian Gross Date: 2004-10-01T08:10:01+09:00 Subject: Re: Regexp question Mark Probert wrote: > Hi, Rubyists. Moin! > 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? This works, (even with escaped escape characters) but you might be better off doing it by hand to keep complexity low: > irb(main):025:0> str = "hello;world;foo\\;bar;no escape\\\\;blar"; puts str > hello;world;foo\;bar;no escape\\;blar > => nil > irb(main):026:0> str.scan(/(?:(?!\\).(?:\\{2})*\\;|[^;])+/).map { |str| str.gsub(/\\(.)/, '\1') } > => ["hello", "world", "foo;bar", "no escape\\", "blar"] Regards, Florian Gross