Skip to content

Instantly share code, notes, and snippets.

@bigimot
Created September 25, 2012 10:26
Show Gist options
  • Save bigimot/736ef42a782c62154a77 to your computer and use it in GitHub Desktop.
Save bigimot/736ef42a782c62154a77 to your computer and use it in GitHub Desktop.
v = ["software", "machine"]
loose_words_array = [] # will remain empty
exact_words_array = [] # becomes ["software"]
ignore_negative_array = [] # will remain empty
v.each do |word|
ignore_negative_array << word.gsub!("-", "") if word.starts_with?("-")
if word.starts_with?("/") && word.ends_with?("/")
exact_words_array << word.gsub("/", "")
else
loose_words_array << word.gsub("/", "")
end
end
sentance = "photo editing software and paint you"
words_caught = sentance.scan(/(?:#{loose_words_array.join("|")})|(?:\b(?:#{exact_words_array.join("|")})\b)/) # returns ["", "", "", "", "", "", "", "", "", "", "", "", "software", "", "", "", "", "", "", "", "", ""]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment