in reply to How do I replace all characters in a string with X's except the last 4 character
Update: Looks like this solution lost bigtime in the benchmarks, which is no surprise. It replaces each character one by one, and each time checks if the next 1-4 characters are among the last four. Hardly effective... It is a good example on the fact that regexps are costly, and not always the best solution. :)#!/usr/bin/perl -w use strict; $_ = '1234567890'; s/.(?!.{0,3}$)/x/g; print;
|
|---|