From: David Alan Black Date: 2002-05-07T23:54:23+09:00 Subject: Re: RegExp zero-width negative lookahead Hello -- On Tue, 7 May 2002, Lars Christensen wrote: > > Hi, > > I'm puzzled why this doesn't work the way I expect it to. > > "xxoxxxoxx" =~ /(?!x)ox+o(?!x)/ #=> nil (ok) > "xx oxxxoxx" =~ /(?!x)ox+o(?!x)/ #=> nil (ok) > "xx oxxxo xx" =~ /(?!x)ox+o(?!x)/ #=> 3 (ok) > "xxoxxxo xx" =~ /(?!x)ox+o(?!x)/ #=> 2 (huh!?) > > Why is the string matched in the last case? Because the first 'o' (or really the zero-width point just to its left) satisfies (?!x), but without being consumed. Then that same 'o' satisfies /o/, and is consumed. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav