From: Mikel Lindsaar Date: 2008-03-19T18:02:41+09:00 Subject: Re: Split string at spaces, but not when inside quotation marks? On Wed, Mar 19, 2008 at 6:53 PM, Peter Bunyan wrote: > I want to be able to split a string at the space, unless the spaces are > inside question marks. I've got a solution, but it makes baby Jesus cry: string = 'This is one solution "that uses a while loop" but I think "someone can do it with map"' quotes = [] while string =~ /".*?"/ quotes << string.slice!(/".*?"/) end p quotes + string.split(' ') #=> ["\"that uses a while loop\"", "\"someone can do it with map\"", "This", "is", "one", "solution", "but", "I", "think"] Mikel http://lindsaar.net/