Wednesday, April 11, 2012

Replace only up to N matches on a line

In Perl, how to write a regular expression that replaces only up to N matches per string?



I.e., I'm looking for a middle ground between s/aa/bb/; and s/aa/bb/g;. I want to allow multiple substitutions, but only up to N times.





No comments:

Post a Comment