Moritz thanks again for your insight, it helped me greatly. I pushed the RegexList Movable Type plugin to github.

The plugin is a tag modifer, meaning you place it into any Movable Type tag that outputs text. The modifier has three arguments. One specifies the substrings to process, and the other two are the "search" regex expression and the replace expression. The result of course is an array of processed substrings which are passed directly within the parent tag to a Movable type array variable (via the built-in setvar modifier). The optional fourth argument to the regex_list modifier defines an alternate capture variable (1-9) to the first match expression (the default is the whole match ($&). I've pasted the main module code below.

package RegexList::Plugin; use strict; use MT 4; sub regex_list { my ( $str, $val, $ctx ) = @_; my $app = MT->app; my @matches; my @subs; # Requires an array die "regex_list requires multiple arguments." unless ref($val) eq 'A +RRAY'; my $subst_patt = $val->[0]; my $replace = $val->[1]; my $match_patt = $val->[2]; my $capture = $val->[3]; # Restrict $capture to single-digit or default is & $capture = $capture =~ /^\s*(\d)\s*/; $capture = ($capture || '&'); #store match from first regex into an array if ( $match_patt =~ m!^(/)(.+)\1([A-Za-z]+)?$! ) { $match_patt = $2; if ( my $opt = $3 ) { $opt =~ s/[ge]+//g; # Mode modifier is moved into the regex using ($modifier) syntax $match_patt = "(?$opt)" . $match_patt; } my $re = eval {qr/$match_patt/}; if ( defined $re ) { eval { while ($str =~ /$re/go) { no strict 'refs'; push (@matches, $$capture); use strict 'refs'; $app->log({ message => "Pushed '" . $& . "' to matches." }); } }; if ($@) { return $ctx->error("Invalid regular expression: $@"); } } } if ( $subst_patt =~ m!^(/)(.+)\1([A-Za-z]+)?$! ) { $subst_patt = $2; my $global; if ( my $opt = $3 ) { $global = 1 if $opt =~ m/g/; $opt =~ s/[ge]+//g; # Mode modifier is moved into the regex using ($modifier) syntax $subst_patt = "(?$opt)" . $subst_patt; } my $re = eval {qr/$subst_patt/}; if ( defined $re ) { $replace =~ s!\\\\(\d+)!\$1!g; # for php, \\1 is how you write +$1 $replace =~ s!/!\\/!g; for my $m (@matches) { eval '$m =~ s/$re/' . $replace . '/o' . ( $global ? 'g' : '' ) +; push (@subs, $m); $app->log({ message => "Pushed '" . $m . "' to subs." }); if ($@) { return $ctx->error("Invalid regular expression: $@"); } } } } return \@subs; } sub mt_log { my ($app, $msg) = @_; $app->log({ message => $msg }); } 1;

In reply to Re^2: capture global substituion inot an array by wrinkles
in thread capture global substitution in an array by wrinkles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.