Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Counting characters within regexp

by jwkrahn (Abbot)
on May 09, 2021 at 02:59 UTC ( [id://11132294]=note: print w/replies, xml ) Need Help??


in reply to Counting characters within regexp

A bit shorter:

use strict; use warnings; my @email = ( 'someone@example.co.uk', 'andrew.test@some.company.co.uk', 'jo@abc.com', ); foreach my $em(@email) { print "$em - "; $em =~ /^(\w[\w.])(.*)(\@\w\w)(.*)(\.\w+)$/; $em = $1 . '.' x length($2) . $3 . '.' x length($4) . $5; print "$em\n"; }

Or, you may like this:

use strict; use warnings; my @email = ( 'someone@example.co.uk', 'andrew.test@some.company.co.uk', 'jo@abc.com', ); for my $em ( @email ) { print "$em - "; ( my $at_pos = rindex $em, '@' ) > 0 or die "$em: invalid email ad +dress.\n"; ( my $dot_pos = rindex $em, '.' ) > $at_pos or die "$em: invalid e +mail address.\n"; tr//./c for substr( $em, 2, $at_pos - 2 ), substr( $em, $at_pos + +3, -( length( $em ) - $dot_pos ) ); print "$em\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132294]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-24 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found