Regular Expressions 101

Community Patterns

Community Library Entry

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