Search query

hi @ all
Has anyone an idea, how I can put a query into a array with regex like
the example below:

-> query = 'ruby + "ruby on rails"'
-> array = ["ruby ruby on rails", "ruby", "ruby on rails"]

···

--
Posted via http://www.ruby-forum.com/.

In the given case, you can use this:

array = query.split(/\s+\+\s+/).map {|str| str.tr('"', '')}
array.unshift(array.join(' '))

This should give you a starting point. However, depending on the
allowed syntax for your queries, this may not work in all cases. E.g.,
if you don't require whitespace on either side of the '+', the first
line should probably be:

array = query.split(/\+/).map {|str| str.strip.tr('"', '')}

···

On Feb 18, 10:22 am, "K. R." <m...@palstek.ch> wrote:

hi @ all
Has anyone an idea, how I can put a query into a array with regex like
the example below:

-> query = 'ruby + "ruby on rails"'
-> array = ["ruby ruby on rails", "ruby", "ruby on rails"]
--
Posted viahttp://www.ruby-forum.com/.