-
-
Save bigimot/736ef42a782c62154a77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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