From: "Peña, Botp" Date: 2008-03-19T18:09:26+09:00 Subject: Re: Split string at spaces, but not when inside quotation marks? From: Peter Bunyan [mailto:peter.bunyan@gmail.com] # 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 ^^^^^^^^^^^ i think you meant quotation marks, no? # Jesus cry: # http://pastebin.com/m6db29d1e that is one way and it does not look bad. there are many ways, of course. # Any better ideas? im not sure if this is better, but irb(main):071:0> x => "this \"this too \" not this \"these too \" not these " irb(main):072:0> x.split(/\s*?(".*?")\s*?/).map{|x| x=~/^".*"$/ ? x : x.split}.flatten => ["this", "\"this too \"", "not", "this", "\"these too \"", "not", "these"] # Is there already a built-in method to do # this (or even one in ActiveSupport)? i do not know of ActiveSupport in ruby. Are you talking about rails? kind regards -botp