From: Rick DeNatale Date: 2007-05-04T03:30:46+09:00 Subject: Re: Regular expression - first two alphabets of a string On 5/3/07, Abhijit Gadgil wrote: > def matchaa (str) > > if str.match(/^aa/) > return true > else > return false > end > end > > On 5/3/07, Ravi Singh wrote: > > Hi All, > > > > I learning regular expressions in Ruby and I want to do the following > > thing with a strings > > > > "A sting should not start with two a i.e aa" > > > > example > > > > "aa xyz" - wrong > > "axyz" - is fine > > "a xyz" is fine > > 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) => # -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/