Rob Dixon wrote: > > As far as lookahead expressions are concerned, Perl functions identically > to Flex. It is called zero-width lookahead because it matches a zero-width > /position/ in the string instead of a sequence of characters. If I write > > '123456' =~ /\d\d\d(...)/ > > then '456' will be captured as the first three characters were consumed by > the preceding pattern. However if I write > > '123456' =~ /(?=\d\d\d)(...)/ > > then '123' will be captured instead because the lookahead pattern has zero > width. > >> The other question I have is - how does regex engine decide that it has >> to move further its scanner by 1 character everytime since I get output >> 123 234 >> 345 456 >> when I run this script ? > > The engine moves as far through your target string as it needs to to find > a new match. If I write > > '1B3D5F' =~ /(?=(.\d.))/g; > > then the engine will find a match at only every second character, and if I > use a much simpler zero-width match, just > > 'ABCDEF' =~ //g > > then the regex will match seven times - at the beginning and end and > between every pair of characters
That will only work if there are no previous patterns in your program otherwise: perldoc perlop [ snip ] If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead. In this case, only the "g" and "c" flags on the empty pattern is honoured - the other flags are taken from the original pattern. If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match). John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/