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)
    #...

Leave a Comment