fork download
  1. subject = 'this, "what I need", to, do, "i, want, this", to, work'
  2. regex = /"([^"]+)"|[^, ]+/
  3. # put Group 1 captures in an array
  4. mymatches = []
  5. subject.scan(regex) {|m|
  6. $1.nil? ? mymatches << $& : mymatches << $1
  7. }
  8. mymatches.each { |x| puts x }
  9.  
Success #stdin #stdout 0.01s 7456KB
stdin
Standard input is empty
stdout
this
what I need
to
do
i, want, this
to
work