On Mon, 2008-12-01 at 02:57 +0100, Jenda Krynicky wrote: > OTOH, he can match the innermost [block]...[/block], remove it or > replace by something that doesn't contain either "tag", match the > next one ... It would not be pretty, but it would be doable. > > And actually if there really is just one tag and if we can assume > that the text doesn't contain \x01 nor \x00 we might use a trick: > > $text = <<'*END*'; > [block] > this is a block > [block] > this is another block > [/block] > first block ends > [/block] > *END* > > print "TEXT: $text\n\n"; > $text =~ s/\[block\]/\x01/g; > print "TEXT: $text\n\n"; > $text =~ s/\[\/block\]/\x00/g; > > print "TEXT: $text\n\n"; > 1 while ($text =~ s{\x01([^\x00\x01]*)\x00}{ > print "found '$1'\n\n"; 'HERE WAS BLOCK' > }ge); > print "TEXT: $text\n\n"; > > Now whether this is of anyuse to ZuLuuuu noone can tell. >
If there were only two levels of nesting, then the data structure would have bounded, nested contexts. These can be parsed with a FSA. A stack is not needed. -- Just my 0.00000002 million dollars worth, Shawn The key to success is being too stupid to realize you can fail. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/