From: Joel VanderWerf Date: 2005-12-02T17:47:57+09:00 Subject: Re: FasterCSV col separator Kev Jackson wrote: > Hi all, > > I'm using FasterCSV and I can't seem to get the syntax correct for using > '|' (the pipe character) for the column separator > > I have > > FasterCSV.parse(csv_file, { :col_sep => "|" }) do |row| > p row > end > > but this fails with > > invalid regular expression; there's no previous pattern, to which '+' > would define cardinality at 4: /\A|+/ > > is this a known bug? > > Kev > > Probably, the col_sep value is simply being interpolated into a regex, instead of first being treated with Regexp.escape. You can do the escaping yourself: irb(main):001:0> /\A|+/ =~ "foo" SyntaxError: compile error (irb):1: invalid regular expression; there's no previous pattern, to which '+' would define cardinality at 4: /\A|+/ from (irb):1 irb(main):002:0> /\A\|+/ =~ "foo" => nil irb(main):003:0> /\A\|+/ =~ "|foo" => 0 irb(main):004:0> s = "|" => "|" irb(main):005:0> Regexp.escape s => "\\|" I don't know anything about FasterCSV, but maybe the author should consider escaping a string value for :col_sep before interpolating it in a regexp. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407