in reply to Re: Extracting regex from string
in thread Extracting regex from string
Also, the n$ "format parameter index" attribute of the sprintf format specifier can free you from the capture variable lockstep of $1 .. $n:
Both safe and flexible.c:\@Work\Perl\monks>perl -wMstrict -le "my $template = 'all the %3$s %1$s %2$s'; my $extract = 'all at sea in ships'; ;; if ($extract =~ m{ \A all \s+ (\w+) \s+ (\w+) \s+ in \s+ (\w+) \z }xm +s) { my $string = sprintf $template, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13; print qq{>$string<}; } " >all the ships at sea<
Give a man a fish: <%-{-{-{-<
|
|---|