From: Jeff Wood Date: 2005-11-22T04:44:20+09:00 Subject: Re: Regular Expressions and Ruby ------=_Part_39200_2075857.1132602255033 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'll have to go look @ that one ... haven't played with it yet. j. On 11/21/05, Christian Neukirchen wrote: > > Jeff Wood writes: > > > well, not that it's perfect, but I would do something like: > > > > elements =3D %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 Uu= n > Uuu > > Uub Uuq Uuh Uuo Ds La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Ac Th P= a > 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 > > #=3D> [ "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 > > -- "Remember. Understand. Believe. Yield! -> http://ruby-lang.org" Jeff Wood ------=_Part_39200_2075857.1132602255033--