Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: regex for nested "<"/">'

by tybalt89 (Parson)
on Feb 13, 2020 at 17:00 UTC ( #11112926=note: print w/replies, xml ) Need Help??


in reply to Re: regex for nested "<"/">'
in thread regex for nested "<"/">'

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11112811 use warnings; my $input = <<ENDOFSTRING; beginning a bend before stuff begin one begin three end five end after stuff beginning a bend ENDOFSTRING print $input, '-' x 70, "\n"; my $level = 0; my $nested = $input =~ s/(\bbegin\b)|(\bend\b)|./ ( $1 && $level++, $level ? $& : '', $2 && $level--)[1] /gesr; print "$nested\n";

Outputs:

beginning a bend before stuff begin one begin three end five end after stuff beginning a bend ---------------------------------------------------------------------- begin one begin three end five end

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2020-04-01 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (186 votes). Check out past polls.

    Notices?