in reply to Removing only the first instance with RegEx
ors/\(// unless /\)/; s/\)// unless /\(/;
since at most only one of the substitutions is needed.if (! /\)/) { s/\(// } elsif (! /\(/) { s/\)// }
These don't ensure balanced parens, as Abigail's answer does, but that wasn't your question. In each case, the first occurrence of a parenthesis will be removed, if there is no opposite parenthesis found. That means, for example, that
)foo(
would be left alone, as would
(a b) c) d)
or any other line that includes both types of parentheses.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Removing only the first instance with RegEx
by Anonymous Monk on Nov 06, 2003 at 20:24 UTC |