# Search query

**URL:** <https://www.ruby-forum.com/t/search-query/129439>\
**Category:** Ruby\
**Created:** [February 18, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/search-query/129439 "2008-02-18T17:22:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 18, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/search-query/129439/1 "2008-02-18T17:22:50Z")

</div>

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”]

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [February 19, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/search-query/129439/2 "2008-02-19T17:23:54Z")

</div>

On Feb 18, 10:22 am, “K. R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/.

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