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

Re: [FWP] innermost first parsing



>>>>> "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'
Jeff>           |
Jeff>           E+ (?! ND )    # match /E+/ if NOT 'END'
Jeff>         )
Jeff>         [^BE]*
Jeff>       )*
Jeff>     )
Jeff>     END
Jeff>   }xs;

I think this is probably just as workable, and more reusable:

    while ($text = s/
      BEGIN
        ((
          (?!BEGIN|END) # not looking at BEGIN or END
          . # inch along
        )*)
      END
    /SOMETHING/xs) {
      "do something with $1";
    }

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. :)

Just another guy who is good at stress-testing regexen... :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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