Regular expression for email in flex

278 views Asked by At

I am trying to wirte a regular expression for emails in JFlex. So far I tried with this

L=[a-zA-Z_]+
D=[0-9]+    
email=[^(.+)@(\S+)$]
%{
    public String lexeme;
%}
%%
{L}({L}|{D})* {lexeme=yytext(); return Identi;}
("(-"{D}+")")|{D}+ {lexeme=yytext(); return Number;}
{email} {lexeme=yytext(); return Email;}
 . {return ERROR;}

When I test with an email, the lexer is not matching any email. How to match email?

1

There are 1 answers

4
coding2 On

I found the solution:

alphaNumeric=({L}+|{L}+{D}+)+
email={alphaNumeric}"@"{alphaNumeric}"."({L}+|{L}+"."{L}+)

This is the regular expression