![]() |
|
Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: replace a string multiple timesby Loops (Curate) |
on Nov 15, 2014 at 11:25 UTC ( #1107301=note: print w/replies, xml ) | Need Help?? |
One way to do this is by putting what you're trying to repeat inside parentheses, and then use the $1 variable which will contain the matching contents: gives:
The $& variable contains the contents of your entire match without using the parentheses even:
And prints the same thing but can have performance issues if you're using a version of Perl prior to version 5.20. And in either case above, if you only want to match the entire word "int" and not when it's part of another word, use \b to designate a word boundary: outputs:
In Section
Seekers of Perl Wisdom
|
|