From: Robert Klemme Date: 2007-05-04T16:35:04+09:00 Subject: Re: Regular expression - first two alphabets of a string On 03.05.2007 20:30, Rick DeNatale wrote: > 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) > => # What exactly do you gain by using lookahead instead of a normal match? Kind regards robert