XP is just a number | |
PerlMonks |
Re: bracket processingby rajaman (Sexton) |
on Mar 31, 2020 at 20:56 UTC ( [id://11114868]=note: print w/replies, xml ) | Need Help?? |
Thank you Monks, great points all! As suggested by @Ken and @AnonymousMonk, let me elaborate the problem. The overall goal is to remove all types of brackets from 'noisy' text (e.g html content/tweets etc.), thereby 'sanitize' text. The brackets may appear in text in any number and in any form (edge cases), the idea is to remove content from within all non-overapping, longest-extending, balanced brackets regardless of their types. Strings that have unbalanced brackets can be ignored. Flanking characters of brackets may be among (\s or \. or \; or \: or \,). The below script from Ken's & AnonymousMonk's suggestions works well if there is just one 'big' bracket, as: Program: Output: 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: The desired output though should have the second bracket also removed, something along the lines: Desired output:'The parentheses.'; Pattern1removed:'(use {of})' Pattern2removed:'(indicates that the (writer [considered] the {information}) less <important—almost> an afterthought)' How can such cases be addressed? Thanks again your help!
In Section
Seekers of Perl Wisdom
|
|