in reply to Counting characters within regexp
something like
DB<98> say "$_:\t", $_ =~ s/(\w\w).*\@.*(\.\w*)/$1...\@...$2/r for q +w/someone@example.co.uk andrew.test@some.company.co.uk jo@abc.com/ someone@example.co.uk: so...@....uk andrew.test@some.company.co.uk: an...@....uk jo@abc.com: jo...@....com
?
YMMV
FWIW your code is (mostly) OK, but you should really always do it in an if-block to test for a successful match first
if( $em =~ /^(\w[\w|\.]).*@(\w\w).*\.(\w+)$/ ) { $em = $1 . '.' x (length($name) - 2) . "\@$2" . '.' x (length($com +p) - length($3) - 2) . $3; }
and you might get bitten by variable interpolation if you don't escape the "@" in a regex: \@
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting characters within regexp
by Bod (Parson) on May 09, 2021 at 09:37 UTC |