From: Rick DeNatale Date: 2007-05-05T03:50:03+09:00 Subject: Re: Regular expression - first two alphabets of a string On 5/4/07, Robert Klemme wrote: > On 03.05.2007 20:30, Rick DeNatale wrote: > > > > Or use a negative lookahead: > > irb(main):001:0> re = /^(?!aa)/ > > => /^(?!aa)/ > > irb(main):002:0> "aa xyz".match(re) > > => nil > > irb(main):003:0> "axyz".match(re) > > => # > > irb(main):004:0> "a yz".match(re) > > => # > > What exactly do you gain by using lookahead instead of a normal match? The OP was asking for an RE which matched anything which DIDN'T start with aa. The proposal using if else got it backwards. Of course you could also just negate the results of the match and use !str.match(/aa/) If you just wanted a test. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ IPMS/USA Region 12 Coordinator http://ipmsr12.denhaven2.com/ Visit the Project Mercury Wiki Site http://www.mercuryspacecraft.com/