I would like to extract an email address which is obfuscated with hyphens in that form: f-o-o-@-e-x-a-m-p-l-e-.-c-o-m
What I did so far is:
String email = "f-o-o-@-e-x-a-m-p-l-e-.-c-o-m";
Pattern p = Pattern.compile("((\\w-)+)@-((\\w-)+)\\.-((\\w-){1,}\\w{1,6})");
Matcher m = p.matcher(email);
while (m.find()) {
email = email.replace("-", "");
}
System.out.println(email);
But I wonder, what if the email already have a hyphen “-” for example: foo-with-hyphen@example.com or foo@example-hyphen.com if theos mails obfuscated the same way above, my code won’t work. How could I solve this?
Sounds like what you want is this:
The
.pattern matches any character while\wmatches only digits and letters.