misterperl has asked for the wisdom of the Perl Monks concerning the following question:
I want a regex to create a variable number $n instances of a block with access TO the value of n for the nth instance, like if $n==3 , and my block is
My regex would change it tocat man
like s/(cat\nman\n)/$n $1($n times)/1 cat man 2 cat man 3 cat man
right now I'm doing this in a tight loop like:
$block .= "$_ cat\nman\n" for 1..$n;
but is there a regex I can use? TY!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can I get some help with a regex please
by hv (Prior) on Jun 13, 2023 at 16:13 UTC | |
Re: Can I get some help with a regex please
by choroba (Cardinal) on Jun 13, 2023 at 15:45 UTC | |
by misterperl (Friar) on Jun 13, 2023 at 16:02 UTC | |
Re: Can I get some help with a regex please
by AnomalousMonk (Archbishop) on Jun 13, 2023 at 17:32 UTC | |
by misterperl (Friar) on Jun 14, 2023 at 14:16 UTC | |
by cavac (Prior) on Jun 14, 2023 at 21:52 UTC | |
Re: Can I get some help with a regex please
by ikegami (Patriarch) on Jun 13, 2023 at 18:13 UTC |