laziness, impatience, and hubris | |
PerlMonks |
Re: strip out anything inbetween bracketsby cog (Parson) |
on Apr 05, 2005 at 14:07 UTC ( [id://444984]=note: print w/replies, xml ) | Need Help?? |
The naive approach would be
$string =~ s/\(.*\)//; Which would do the trick in this particular case, but would convert "this is a (blah) and this is not a (blah)" in "this is a ", which is why you should use a non-eager quantifier: $string =~ s/\(.*?\)//; This does the trick... Don't forget, however, to use the /g switch (for global substitutions). Also, your example has the result as being "this is a" (notice there's no space after the a...) If that's what you want, you just need to include \s* on both ends of your regular expression... OTOH, that would turn "this is a (blah) bleh" into "this is ableh", which is probably not what you want... O:-)
In Section
Seekers of Perl Wisdom
|
|