# FasterCSV col separator

**URL:** <https://www.ruby-forum.com/t/fastercsv-col-separator/49299>\
**Category:** Ruby\
**Created:** [December 2, 2005, 9:36am UTC](https://www.ruby-forum.com/t/fastercsv-col-separator/49299 "2005-12-02T09:36:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [December 2, 2005, 9:36am UTC](https://www.ruby-forum.com/t/fastercsv-col-separator/49299/1 "2005-12-02T09:36:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [December 2, 2005, 9:48am UTC](https://www.ruby-forum.com/t/fastercsv-col-separator/49299/2 "2005-12-02T09:48:58Z")

</div>

Kev J. wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![kevin.jackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/85f322/32.png) [@kevin.jackson](https://www.ruby-forum.com/u/kevin.jackson)\
**Post date:** [December 2, 2005, 4:11pm UTC](https://www.ruby-forum.com/t/fastercsv-col-separator/49299/3 "2005-12-02T16:11:48Z")

</div>

On Dec 2, 2005, at 2:34 AM, Kev J. wrote:

> 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?

It’s now known and fixed. Update to the freshly uploaded FasterCSV  
0.1.4 and this should be just a bad memory. I’ve added test cases to  
monitor this, so it shouldn’t happen again. Sorry about that.

James Edward G. II
