From: Christian Neukirchen Date: 2005-11-22T02:48:08+09:00 Subject: Re: Regular Expressions and Ruby Jeff Wood writes: > well, not that it's perfect, but I would do something like: > > elements = %w( He LI Be C O Ne Na Mg Al Si S Cl Ar Ca Sc Ti Cr Mn Fe Co Ni > Cu Zn Ga Ge As Se Br Kr Rb Sr Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te Xe Cs > Ba Hf Ta Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Rf Db Sg Bh Hs Mt Uun Uuu > Uub Uuq Uuh Uuo Ds La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Ac Th Pa Np > Pu Am Cm Bk Cf Es Fm Md No Lr H B N F P V Y I W Uaal ) > > class Array > def to_re( regex_modifier ) > eval "/#{ self.join "|" }/#{ regex_modifier }" > end > end > > "present".scan elements.to_re( "i" ) # the "i" means case insensitive > #=> [ "pr", "es", "n" ] > > ... hope that helps. I'm sure there are more efficient regex patterns for > this, but I couldn't imagine anything that was easier to write. Regexp.union exists. > Jeff Wood -- Christian Neukirchen http://chneukirchen.org