From: Matthew Moss Date: 2006-01-07T10:54:40+09:00 Subject: Re: Splitting strings on spaces, unless inside quotes > some words "some quoted text" some more words > > would get split up into: > > ["some", "words", "some quoted text", "some", "more", "words"] s = 'some words "some quoted text" some more words sa = s.split(/"/).collect { |x| x.strip } (0...sa.size).to_a.zip(sa).collect { |i,x| (i&1).zero? ? x.split : x }.flatten