Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Don't ask to ask, just ask
 
PerlMonks  

Re^2: strip out anything inbetween brackets

by deibyz (Hermit)
on Apr 05, 2005 at 15:21 UTC ( #445009=note: print w/ replies, xml ) Need Help??


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


Comment on Re^2: strip out anything inbetween brackets
Download Code
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://445009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2013-05-24 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (495 votes), past polls