From: Robert Klemme Date: 2004-03-11T21:09:35+09:00 Subject: Re: Regular Expression for D(elimiter) Separated Values File "Iki" schrieb im Newsbeitrag news:ad334b15.0403110224.4d3d5b2@posting.google.com... > Hi all, > > I thought I could parse a dsv file with say a ';' delimiter > (escaped with a backslash where appropriate) just by using > a regexp such as /(?=[^\\]);/x and String#split > > > "eggs\\;bread;butter".split(/(?=[^\\]);/x)' > => ["eggs\\", "bread", "butter"] > > > but .. > > "eggs;\\bread;butter".split(/;(?=[^\\])/x)' > => ["eggs;\\bread", "butter"] > > Am I missing something? Yes, Ruby regular expressions can't do lookbehind, which is what you need for the escaping. But you can use scan: irb(main):005:0> "eggs\\;bread;butter".scan /(?:[^\\;]+|\\.)+/ => ["eggs\\;bread", "butter"] irb(main):006:0> "eggs\\;bread;butter".scan /(?:[^\\;]|\\.)+/ => ["eggs\\;bread", "butter"] Regards robert