From: George Lunsford Date: 2005-11-22T01:53:54+09:00 Subject: Re: Regular Expressions and Ruby ------=_Part_31171_5386085.1132592028761 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I am matching +i, sorry for leaving that out. I copied the expression from the regex coach, which has that handy checkbox. Thanks for the optimized info for the future. Ruby/Regex coach doesn't seem to like the optimized version though either... On 11/21/05, Christian Neukirchen wrote: > > George Lunsford writes: > > > Hi, I'm new to the list and I hope this is the right place to ask the > > question, but I recently started learning ruby and I was writing a shor= t > > little program to test if a word was made up of symbols from the > periodic > > table. I figured I'd use ruby's built-in regex support, so I ended up > > writing a regex that looks something like this: > > (element1|element2|element3...|elementx)+ > > Basically it's just got all 115 or so of the elements in there, and it'= s > > testing for one or more, right? Unfortunately this doesn't seem to work > > properly as a (nonsense) word like "presenti" should be periodic > according > > to my list of elements, [p][re][se][n][ti]. Now, I can duplicate this > > behavior with the regex coach oddly enough. The problem seems to be tha= t > it > > parses [p][re][s] instead of [se]. I'm wondering if anyone can explain > this > > behavior to me, as I'm new to both regexps and ruby and the only regex > > experience I've had previous to this is in some theory classes. Thanks. > The > > full expression is below. > > > > > (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|Uu= h|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)+ > > Are you matching case insensitive (/i)? > > By the way, an optimized version of that regexp is > > > /(A[cglmr-u]|B[aehikr]|C[adeflmorsu]|D[bsy]|E[rsu]|F[emr]|G[ade]|H[efgos]= |I[nr]|Kr|L[airu]|M[dgnot]|N[abdeiop]|Os|P[abdmortu]|R[abefhnu]|S[bcegimnr]= |T[abcehilm]|U(?:aal|u[bhnoqu])|Xe|Yb|Z[nr]|[BCFHINOPSVWY])+/ > > (Thanks to emacs's regexp-opt) > -- > Christian Neukirchen http://chneukirchen.org > > ------=_Part_31171_5386085.1132592028761--