I’m scanning through a product name to check if a specific string exists in it. Right now it works for a single string, but how can I can scan for multiple strings? e.g. i’d like to scan for both apple and microsoft
product.name.downcase.scan(/apple/)
If the string is detected i get [“apple”]
if not then it returns nil [ ]
You can use regex alternation:
If all you need to know is whether the string contains any of the specified strings, you should better use single match =~ instead of
scan.