search query

K

K. R.

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"]
 
Y

yermej

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,284
Messages
2,571,410
Members
48,103
Latest member
MadieDeitz

Latest Threads

Top