How do I go from this:
"01","35004","AL","ACMAR",86.51557,33.584132,6055,0.001499
to this:
ACMAR, AL
How do I go from this:
"01","35004","AL","ACMAR",86.51557,33.584132,6055,0.001499
to this:
ACMAR, AL
If it is an array — […].grep(/^[A-Z]+$/)
, if string — "…".scan(/[A-Z]+/)
match: \"([A-Za-z].*)\".*\"([A-Za-z].*)\"
replace: \2, \1
This assumes the only fields with letters are those two. A better solution might be to explode on ',' and take the 3rd and 4th string.
You could use this
"(.+)","(.+)","(.+)","(.+)",
and then concatenate capture group 3 and 2
I'm not quite sure why you'd want to parse a CSV file with a Regexp
instead of a CSV parser. It makes your life so much easier:
require 'csv'
CSV.open('/path/to/output.csv', 'wt') do |csv|
CSV.foreach('/path/to/output.csv') do |_, _, state, city|
csv << [state, city]
end
end