I have the following array:
arr = ["lol","test"]
and a code:
matches = content.downcase.split & arr
where content
is a string. This code returns ["lol"]
when content = "Something lol"
, but fails to return anything when content = "Something #lol."
with a comma or hashtag etc. It always fails when there is no exact match.
I'd like to match with the strings in the array as substring. How can this be done by adapting the above code?
Try splitting on non-word boundary as shown below
arr = ["lol","test"]
content = "Something #lol."
p matches = content.downcase.split(/\W/) & arr
Outputs
["lol"]
Sample runs from Try ruby is shown below
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加