laziness, impatience, and hubris | |
PerlMonks |
Regex for replacing multiple nested matchesby Lana (Beadle) |
on Sep 10, 2015 at 18:17 UTC ( [id://1141585]=perlquestion: print w/replies, xml ) | Need Help?? |
Lana has asked for the wisdom of the Perl Monks concerning the following question: Hi Monks! First of all, sorry for the kind of dumb question, but I stuck with it. Maybe there something wrong with planet positions in the sky today. :) (jk) Well, here is a code:
The $string contains three text arrays like ###RAND{a|b|c|d} nested into each other. The a-b-c-d is a text array splitted by a pipe. What I need is process all occurences of the ###RAND{a|b|c|d} arrays in $count passes starting from the last one and moving to the first - to avoid interfering ###RAND{a|b|c|d} vars. Each pass must substitute ###RAND{a|b|c|d} with random element from the a|b|c|d array. As in this example there three nested ###RAND{a|b|c|d} text arrays, the steps should look like this:
How to make the regexp to substitute only the last occurence in each pass? Thank you!Lana
Back to
Seekers of Perl Wisdom
|
|