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
In reply to my versus our in nested regex by Len
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |