in reply to Re: strip out anything inbetween brackets
in thread strip out anything inbetween brackets

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...

Replies are listed 'Best First'.
Re^3: strip out anything inbetween brackets
by tlm (Prior) on Apr 05, 2005 at 15:32 UTC

    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)

        Yes. After I sent that reply I realized that you probably had something else in mind other than the original problem of removing the parens and "everything in between". The latter would arguably require getting rid of the first parens and everything after. Please see my update. As your question suggests, the problem needs defining; what exactly should "everything in between" be defined?

        the lowliest monk