Re: Ruby Code Quiz - How can I parse quoted values with String#split?
"Dan Fitzpatrick" <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <emb38f4d31-128a-405a-bb62-fa29dd7440a2@carbonx> |
line = %("1",'2',3)
delim = ','
# Detect first and last characters being ' or ", if so strip them
line.split(delim).map{|i| (i[0] =~ /["']/ and i[-1] =~ /["']/) ?
i[1...-1] : i}
#=> ["1", "2", "3"]
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>