in reply to bracket processing
Output:####program.pl #!/usr/bin/perl use strict; use warnings; use Text::Balanced 'extract_bracketed'; my $delim = '([{<'; my $prefix = qr{[^\Q$delim\E]*}; my $string = 'The use of parentheses (indicates that the (writer [cons +idered] the {information}) less <important—almost> an afterthought).' +; my @parts = extract_bracketed($string, $delim, $prefix); $parts[2]=~s/\s*$//; print WF1 "pattern:\'$parts[0]\'\n"; print WF1 "rightside of pattern:\'$parts[1]\'\n"; print WF1 "leftside of pattern:\'$parts[2]\'\n";
However, when another non-overlapping bracket appears in the string (e.g. '(use {of})') as shown below, the above script removes just one, as shown below:pattern:'(indicates that the (writer [considered] the {information}) l +ess <important—almost> an afterthought)' rightside of pattern:'.' leftside of pattern:'The use of parentheses'
The desired output though should have the second bracket also removed, something along the lines:$string = 'The (use {of}) parentheses (indicates that the (writer [con +sidered] the {information}) less <important—almost> an afterthought). +'; Output: pattern:'(use {of})' rightside of pattern:' parentheses (indicates that the (writer [consid +ered] the {information}) less <important—almost> an afterthought).' leftside of pattern:'The'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: bracket processing
by kcott (Archbishop) on Apr 01, 2020 at 02:31 UTC | |
by rajaman (Sexton) on Apr 02, 2020 at 02:16 UTC | |
by AnomalousMonk (Archbishop) on Apr 02, 2020 at 04:09 UTC | |
by rajaman (Sexton) on Apr 05, 2020 at 21:00 UTC |