You are all familiar how to match nested balanced parenthesis.
But that expressions is easily extendable to larger start
and finish markers. Here's how you would match a nested
begin/end block.
$re = qr /begin # Start with 'begin', (?: # Followed by (?>[^be]+) # Not a b or e, many times, |b(?!egin) # Or a b not starting 'begin', |e(?!nd) # Or an e not starting 'end', |(??{ $re }) # Or a balanced begin/end block )* # zero or more times end/x; # And an 'end'.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Matching nested begin/ends
by PodMaster (Abbot) on Jul 31, 2002 at 12:17 UTC | |
by Abigail-II (Bishop) on Jul 31, 2002 at 12:49 UTC | |
Re: Matching nested begin/ends
by I0 (Priest) on Aug 01, 2002 at 00:27 UTC | |
Re: Matching nested begin/ends
by jryan (Vicar) on Jul 31, 2002 at 22:44 UTC | |
by Abigail-II (Bishop) on Aug 01, 2002 at 09:19 UTC | |
by jryan (Vicar) on Aug 01, 2002 at 23:16 UTC | |
by Abigail-II (Bishop) on Aug 02, 2002 at 09:30 UTC | |
by jryan (Vicar) on Aug 02, 2002 at 23:04 UTC | |
|
Back to
Cool Uses for Perl