Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Remove text within parenthesis

by jnyman (Acolyte)
on May 08, 2013 at 12:06 UTC ( #1032605=note: print w/ replies, xml ) Need Help??


in reply to Remove text within parenthesis

If you have nested parentheses, the solution is somewhat more complex:

use 5.014; my $s = "a (d (b) (e (f) ) ) c"; say remove_par($s); sub remove_par { my ( $result, $open ); foreach my $ch ( split // => shift ) { $open++ if $ch eq '('; $open-- if $ch eq ')'; $result .= $ch if !$open && $ch ne ')'; } die "non-matching parentheses" if $open; return $result; };


Comment on Re: Remove text within parenthesis
Download Code
Re^2: Remove text within parenthesis
by BillKSmith (Deacon) on May 08, 2013 at 15:29 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2015-07-05 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls