in reply to strip out anything inbetween brackets

In general, it is difficult to deal with balanced delimiters using regexps alone (the problem arises when you have nested parenthesized expressions). You may want to take a look at Text::Balanced.

the lowliest monk

  • Comment on Re: strip out anything inbetween brackets

Replies are listed 'Best First'.
Re^2: strip out anything inbetween brackets
by deibyz (Hermit) on Apr 05, 2005 at 15:21 UTC
    For this simple case, maybe a simple "do while you can" can do the job:

    #!/usr/local/bin/perl local $_="woaaa (nested (parens))"; while (s/\([^()]*\)//){ print "$_\n"; } __OUTPUT__ ouu (nested ) ouu

    But it's possible that I'm missing something...

      Try your code against $_="woaaa (nested (parens)))".

      Update: Well, that's not fair of me, because the parens are not balanced; but it does show that the general problem has wrinkles. Judging by follow-up posts it looks like the OP's problem is simple enough to be dealt with a plain regexp. Text::Balanced shines when you have to process large chunks of text (e.g. source code) with balanced expressions.

      the lowliest monk

        Ok, it returns "woaaa )"

        What should it do? It removes everything "between" parens, but nothing else. If something has to be done with unmatched parens, we're talking about a diferent task, aren't we? =o)