On Wed Mar 25 2009 @ 12:19, Rodrick Brown wrote: > On Wed, Mar 25, 2009 at 12:00 PM, Rick Bragg <li...@gmnet.net> wrote: > > I need a quick regex to strip out the following: > > > > example: > > change "remove-all-this (Keep This)" into just "Keep This" > > > > $s =~ s/.*\((.*)\)/$1/; > > > something like: > > s/ beginning of line up to and including the first ( //g > > s/ starting from and including first ) to end of line //g
But if there's anything after the 'Keep this', you have problems with this version: use strict; use warnings; my $string = 'remove-all-this (Keep this) remove this too'; $string =~ s/.*\(//; $string =~ s/\).*//; print "$string\n"; my $string2 = 'remove-all-this (Keep this) remove this too'; $string2 =~ s/.*\((.*)\)/$1/; print "$1\n" if $1; print "$string2\n"; For $string2, you end up with "Keep this remove this too" since you replace the 'Keep this' back into the rest of the string. (That is, you substitute 'remove-all-this (Keep this)' with 'Keep this'. So if you have anything after the closing paren, you have a problem. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/