I need to match a regex on Java when a string does NOT contains an email anywhere in the string: the beginning, middle or end. For example:
string with no email [match]
myMail@mail.com string with email at the start [no match]
String with myMail@mail.com in the middle [no match]
String with email at the end myMail@mail.com [no match]
myMail@mail.com [no match]
The regex I have managed to come up with so far is an inverse version of a popular email regex:
"^(?![_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$).*$)";
works for me only when I have just an email;
myMail@mail.com [no match]
but I need it to give me no match for ALL the examples containing an email. Any ideas how it can be done? Thanks
edited:
Found the answer by looking at
Regular expression to match a line that doesn't contain a word?
The working line is:
"^((?![_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})).)*$)";
Thanks