The two experimental features which are needed are (??{}) for delayed evaluation and (?>) for telling the engine not to backtrack. A sample script demonstrating the technique:
Run it and start typing in lines. The ones with balanced parentheses will match.#! /usr/bin/perl my $braces; $braces = qr/(\((?:(?>[^\(\)]+)|(??{$braces}))*\))/; while (<>) { if ($_ =~ $braces) { print "Matched '$1'\n\n"; } else { print "No match\n\n"; } }
In reply to Re (tilly) 5: parsing question
by tilly
in thread Re: parsing question
by sliles
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |