sub formatCode{ my $code = shift; my $prev_header = 0; # takes care of closing + divs for (split /\n/, $code) { # No need to remove new +lines if (/^\s*$/) { next } # Skip blank lines elsif ( /^(.*?)\[ ([^\]]*) \](.*)/x ) { # If line is a h +eader... print "$1</div>" if $prev_header; # close prev div, if +there was one... print qq(<div class="$2">$3); # print current div.. +. $prev_header = 1; # and set current div + flag. } else { print "$_<br />" } # Simply print non-head +er lines } print "</div>" if $prev_header; # You always have to cl +ose last div, so just do it here }
In reply to Re^2: Recursive Regex
by deMize
in thread Parsing using Regex and Lookahead
by deMize
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |