Len has asked for the wisdom of the Perl Monks concerning the following question:
Why do I have to use our $regex instead of my $regex to get the expected result ?use strict; our $regex = qr /( # Start capture \( # Start with '(', (?: # Followed by (?>[^()]+) # Non-parenthesis |(??{ $regex }) # Or a balanced () block )* # zero or more times \) # Close capture )/x; # Ending with ')' my $text = '(outer(inner(most inner)))'; $text =~ /$regex/gs; print "$1\n";
our $regex prints (outer(inner(most inner)))
my $regex prints (most inner)
Len
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: my versus our in nested regex
by BrowserUk (Patriarch) on Oct 18, 2003 at 17:08 UTC | |
by liz (Monsignor) on Oct 18, 2003 at 17:19 UTC | |
by Anonymous Monk on Oct 18, 2003 at 17:20 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2003 at 17:44 UTC | |
by demerphq (Chancellor) on Oct 18, 2003 at 18:10 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2003 at 18:56 UTC | |
| |
by Anonymous Monk on Oct 18, 2003 at 18:36 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2003 at 18:40 UTC | |
Re: my versus our in nested regex
by shenme (Priest) on Oct 18, 2003 at 17:02 UTC | |
Re: my versus our in nested regex
by pernod (Chaplain) on Oct 21, 2003 at 10:33 UTC |