We have a search website where the user can type in individual words
separated by spaces and/or phrases enclosed in single or double quotes.
We are looking for a way to obtain a list of words and phrases from the
search string.
Can someone help?
We have a search website where the user can type in individual words
separated by spaces and/or phrases enclosed in single or double quotes.
We are looking for a way to obtain a list of words and phrases from the
search string.
Can someone help?
string.scan(/\w+/)
to give an array of words, or
string.split(/\W+/)
to split on non-words. You can string.gsub(/["’]/, ‘’) if you want to
get rid of quotes.
If the input string is:
Java Ruby ‘Ruby on rails’ “software development” “technology”
The list of words should be:
Java
Ruby
Ruby on rails
software development
technology
With your approach, the result will be:
Java
Ruby
Ruby
on
rails
software
development
technology
Alex Y. wrote:
Yash wrote:
Hi
We have a search website where the user can type in individual words
separated by spaces and/or phrases enclosed in single or double quotes.
We are looking for a way to obtain a list of words and phrases from the
search string.
Can someone help?
string.scan(/\w+/)
to give an array of words, or
string.split(/\W+/)
to split on non-words. You can string.gsub(/["’]/, ‘’) if you want to
get rid of quotes.