in reply to How do I replace all characters in a string with X's except the last 4 character

Just to show TIMTOWTDI, I add this:
#!/usr/bin/perl -w use strict; $_ = '1234567890'; s/.(?!.{0,3}$)/x/g; print;
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. :)
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.
  • Comment on Re: How do I replace all characters in a string with X's except the last 4 character
  • Download Code