[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

search query

K. R.

2/18/2008 4:23:00 PM

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-....

1 Answer

yermej

2/19/2008 4:19:00 PM

0

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-....

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('"', '')}