in reply to Matching nested parens
I would suggest Regexp::Common:
use warnings; use strict; use Data::Dump; use Regexp::Common qw/balanced/; "(a a (a a)(a a))(b b(b)b b)" =~ /$RE{balanced}{-parens=>'()'}/; dd $&, $'; # ("(a a (a a)(a a))", "(b b(b)b b)")
Though of course there are plenty of other solutions, including Parse::RecDescent, though that might be a little overkill if this is all you're doing. See e.g. regex for nested "<"/">', and note that Text::Balanced is a core module.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching nested parens
by BernieC (Pilgrim) on Oct 01, 2020 at 21:24 UTC | |
by BernieC (Pilgrim) on Oct 01, 2020 at 22:25 UTC | |
by AnomalousMonk (Archbishop) on Oct 01, 2020 at 23:24 UTC | |
by BernieC (Pilgrim) on Oct 06, 2020 at 15:29 UTC |