Im trying to figure out how i can remove certain characters in an email address before the domain name using nothing but a simple regex and replaceAll
in Java.
In email addresses,
- Need to remove any number of
.
before@<domain name>
- Also remove anything between
+
up to@
but not including@
. For instance in[email protected]
should be[email protected]
.
So far I have,
class Main {
public static void main(String[] args) {
String matchingRegex = "(\\.|(\\+.*(?=@)))";
System.out.println("[email protected]".replaceAll(matchingRegex, ""));
}
}
which replaces everything including the domain name.
joebloggs@gmailcom
What i really need is [email protected]
.
Can this be achieved with regex alone ?