Match a string against multiple patterns
Use Regexp.union
to combine them:
union(pats_ary) → new_regexp
Return a
Regexp
object that is the union of the given patterns, i.e., will match any of its parts.
So this will do:
re = Regexp.union(prefixes)
then you use re
as your regex:
if name.match(re)
#...
If you can use a single string, it might be faster to write a regex containing the possible values.
e.g.
/(Mr\.|Mrs\.| ... )/.match(name)