Regular Expressions 101

Community Patterns

Mask an email regex II (no TLD)

1

Regular Expression
PCRE (PHP <7.3)

/
(?<=.).(?=[^@]*?.@)|(?:(?<=@.)|(?!^)\G(?=[^@]*$)).(?=.*\.)
/
g

Description

Replaces second to last but one characters with asterisks in email all parts BUT TLD: test01@gmail.com -> t1@g.com

AUTHOR SO link: http://stackoverflow.com/users/3832970/wiktor-stribi%C5%BCew

Submitted by Wiktor Stribiżew - 8 years ago