I am trying to write antlr lexer grammar rule to validate email address I have got most of it working however I am unable to validate that the character '.' does not appear consecutively. For example my code passes the example, [email protected] which it should not. I have tried several regex but nothing seems to work well. Can somebody please help me out here, I have just started learning this so I don't know much. Here is what I have so far.
fragment LOCALCHARS_first_last : [a-zA-Z0-9-_~!$&'()*+,;=:]; //local part must not include character '.'
fragment LOCALCHARS : [a-zA-Z0-9-_~!$&'.()*+,;=:]+;
fragment LOCALPART: LOCALCHARS_first_last LOCALCHARS LOCALCHARS_first_last; //'.' cannot be first or last character
fragment DOMAINPART: [a-zA-Z0-9-.]+;
fragment EMAIL: LOCALPART '@' DOMAINPART;
CHECKEMAIL: (EMAIL) {
System.out.println("valid email: "+getText());
};