in reply to How do I replace certain character if condition exists
Possibly a simplistic solution, but have you tried using negative lookahead? For instance:
Breaking the regex down:abowley@krait:~$ (echo 'Madrid(Spain' && echo 'Madrid(Spain)') | perl +-pe 's/\((?![^)]*\))/ /g;' Madrid Spain Madrid(Spain)
s/ \( # an open bracket (?! # _not_ followed by [^)]* # anything except brackets (e.g. 'Spain') \) # followed by a bracket ) / /gz;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: How do I replace certain character if condition exists
by Bilbo (Pilgrim) on Apr 17, 2003 at 13:41 UTC | |
by kilinrax (Deacon) on Apr 17, 2003 at 16:58 UTC |
In Section
Seekers of Perl Wisdom