[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] innermost first parsing



On Aug 2, abigail@foad.org said:

>On Wed, Aug 02, 2000 at 12:27:58PM -0400, Ronald J Kimball wrote:
>> On Wed, Aug 02, 2000 at 08:54:55AM -0700, Randal L. Schwartz wrote:
>> > >>>>> "Jeff" == Jeff Pinyan <jeffp@crusoe.net> writes:
>> > 
>> > Jeff>   ($first) = $text =~ m{
>> > Jeff>     BEGIN
>> > Jeff>     (
>> > Jeff>       [^BE]*  # 'B' and 'E' are first chars of tags
>> > Jeff>       (?:
>> > Jeff>         (?:
>> > Jeff>           B+ (?! EGIN )  # match /B+/ if NOT 'BEGIN'
>> 
>> > I think yours fails on BEGIN ... BBBBBEGIN ... END ... END
>> > as well, since you grab the multiple B's but only check the first
>> > B for BEGIN'ness. :)
>> 
>> I don't think that's right.  B+(?!EGIN) checks each B for BEGIN-ness.
>> In BBBBEGIN, it will match the first three Bs and reject the fourth, which
>> is followed by EGIN.
>
>No, it checks to see if the last B is followed by EGIN. It will backtrack
>to a previous B only if it is.

Abigail is correct.  /(?:(?!BEGIN)B)+/ checks each B for
BEGIN-ness.  /B+(?!EGIN)/ only checks the last B, and backtracks.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe