RegEx in Ruby for Converting CSV to TSV
In Ruby, what's a regular expression that identifies commas withi开发者_高级运维n quotes (e.g., "dog, cat, foo, bar")? My purpose is converting a CSV file to TSV, and some of my fields contain strings with commas within quotes that I want to preserve.
Does it have to be a regex? Can just Parse the CSV using your fav csv library, and then rejoin using tabs?
require 'csv'
test = '"foo,bar,baz",one,two,three'
CSV.parse_line(test).join("\t")
"foo,bar,baz\tone\ttwo\tthree"
精彩评论