I need to protect the email addresses contained in a text. Ideally find a regular expression that could do it more effectively.
Example:
Hi: My Name is Alex and my mail is alexmail@domain.com but you can reply to alexreply@other.domain.com.
Desired output:
Hi: 我的名字是 Alex,我的邮件是ale****@domain.com但你可以回复 ale****@other.domain.com。
逻辑是:保留前 3 个字符并用 * 替换其余字符,直到@。
a@mail.com => a****@mail.com
ab@mail.com => ab****@mail.com
abc@mail.com => abc****@mail.com
abcd@mail.com => abc****@mail.com
abcde@mail.com => abc****@mail.com
Run Code Online (Sandbox Code Playgroud)
现在,我以这种方式创建了一个保护邮件的功能,但是当它是一个包含多封电子邮件的文本时,我无法使用replaceAll。
public static String protectEmailAddress(String emailAddress) {
String[] split …Run Code Online (Sandbox Code Playgroud)