in reply to pattern matching nested { }'s
which produces:#!/usr/bin/perl use Text::Balanced 'extract_bracketed'; $_ = <<'#END#'; This stays onValidate { stuff in here { other stuff } } This stays too #END# if(/onValidate/) { print substr($_, 0, $-[0]); # before my ($extracted, $remainder) = extract_bracketed(substr($_, $+[0]), + '{}'); print $remainder; # after print "\n## extracted: ##\n$extracted\n"; }
This stays
This stays too
## extracted: ##
{
stuff in here
{
other stuff
}
}
|
|---|