downcase the email address and domain that you want to map first, then find_all regexp matches.
You can use find only to get the first matching "rule".
email = ' bob@luv.southwest.com ' domain_rules = [/craigslist.org/, /evite.com/, /ziprealty.com/, /alleyinsider.com/, /fedexkinkos.com/, /luv.southwest.com/, /fastsigns.com/, /experts-exchange.com/, /feedburner.com/] user, domain = email.split('@').collect { |s| s.downcase } p domain_rules.find_all { |rule| domain[rule] }
Also there is no need for Regexp:
email = ' bob@luv.southwest.com ' matchable_domains = %w{ craigslist.org evite.com ziprealty.com alleyinsider.com fedexkinkos.com luv.southwest.com fastsigns.com experts-exchange.com feedburner.com } user, domain = email.downcase.split('@') p matchable_domains.find_all { |rule| matchable_domains.include?(domain) }
Or you can do ONLY Regexp:
email = ' bob@luv.southwest.com ' regexp = /[A-Z0-9._%+-] +@ (craigslist\.org|evite\.com|ziprealty\.com|alleyinsider\.com|fedexkinkos\.com|luv\.southwest\.com|fastsigns\.com|experts-exchange\.com|feedburner\.com)/ p regexp === email # => true p regexp.match(email) # => #<MatchData " bob@luv.southwest.com " 1:"bob" 2:"luv.southwest.com">il
source share