in reply to bracket processing
Hi,
Just remove the matching string (and whatever's left over) when you find that the RE matches. The matched string will be in $1 as normal and the original string will be trimmed to just the prefix.
Output:use strict; use warnings; use 5.010; use Regexp::Common 'RE_balanced'; my $string = 'The use of parentheses (indicates that the ' . '(writer [considered] the {information}) less ' . '<important—almost> an afterthought).'; my $match = RE_balanced( -parens => '(){}[]<>' ); $string =~ s/${match}.*//; $1 and say ">$_<" for $string, $1;
$ perl 11114819.pl >The use of parentheses < >(indicates that the (writer [considered] the {information}) less <imp +ortant—almost> an afterthought)<
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: bracket processing (updated)
by AnomalousMonk (Archbishop) on Mar 31, 2020 at 05:48 UTC | |
by haukex (Archbishop) on Mar 31, 2020 at 07:25 UTC |