Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Regex: first match that is not enclosed in parenthesis

by hdb (Prior)
on Jun 30, 2013 at 16:53 UTC ( #1041617=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regex: first match that is not enclosed in parenthesis
in thread Regex: first match that is not enclosed in parenthesis

Something like this:

use strict; use warnings; my $input = "1*(2+3)*(3+4)+5*(6+7)"; my $level = 0; my $tab = "| "; my %action = ( '(' => sub { print "\n", $tab x ++$level, shift }, ')' => sub { print "\n", $tab x $level--, shift }, '+' => sub { print "This one>>>" unless $level; print +shift }, 'default' => sub { print shift }, ); ( $action{$_} // $action{'default'} )->($_) for $input =~ /./g;

The additional effort is only worthwhile if you have ambitions beyond your initial question.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041617]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2016-12-04 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (63 votes). Check out past polls.