[英]Regular expression for email in flex
I am trying to wirte a regular expression for emails in JFlex.我正在尝试为 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?
如何匹配电子邮件?
I found the solution:我找到了解决方案:
alphaNumeric=({L}+|{L}+{D}+)+
email={alphaNumeric}"@"{alphaNumeric}"."({L}+|{L}+"."{L}+)
This is the regular expression这是正则表达式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.