in reply to Re^2: Regex for removing Template::Toolkit comments?
in thread Regex for removing Template::Toolkit comments?
#!/usr/bin/perl # https://perlmonks.org/?node_id=1221039 use strict; use warnings; my $someTTstring = <<END; before [% # this is a comment to the end of line foo = 'bar' %] <p>bw, bliako</p> [%# placing the '#' immediately inside the directive tag comments out the entire directive %] [% outside %] [%# placing the '#' immediately inside the directive tag comments out the entire directive [% inside %] %] after END print stripcomments($someTTstring); sub stripcomments { @_ and local $_ = shift; my $answer = ''; $answer .= /\G\[\%#/gc ? stripcomments() x 0 : /\G\[\%/gc ? '[%' . stripcomments() =~ s/#.*//gr . '%]' : /\G\%\]/gc ? return $answer : /\G./gcs ? $& : return $answer while 1; }
Like this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regex for removing Template::Toolkit comments?
by bliako (Abbot) on Aug 27, 2018 at 10:41 UTC | |
by tybalt89 (Monsignor) on Aug 27, 2018 at 13:16 UTC | |
by bliako (Abbot) on Aug 27, 2018 at 14:46 UTC |