On Wed, Mar 25, 2009 at 13:21, Telemachus <telemac...@arpinum.org> wrote:
snip
>    my $string2 = 'remove-all-this (Keep this) remove this too';
>
>    $string2 =~ s/.*\((.*)\)/$1/;
snip

If $string2 may contain more than one pair of parentheses, you will want to say

$string2 =~ s/.*\((.*?)\)/$1/;

or

$string2 =~ s/.*\(([^)]*)\)/$1/;

The first uses a non-greedy match (i.e. it matches the smallest string
that allows the match to succeed rather than the default match of
largest string that allows the match to succeed).  The second matches
all characters other than ) up to the next ).

If you have nested parentheses (e.g. "foo ( bar ( baz ) ) quux)"), all
bets are off, and you are better off writing a parser than trying to
use a regex.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to