[英]What is the optimized regex to match the email pattern in java
I am using the below regex in my program for matching the email pattern which is working fine. 我在程序中使用以下正则表达式来匹配正常工作的电子邮件模式。 Pattern :
模式:
(?i)[a-z0-9!#$%&*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])+
It matching all the emails correctly. 它正确匹配所有电子邮件。 But now my use case is to apply above email regex for content which contains very large junk values.
但是现在,我的用例是在电子邮件正则表达式之上应用包含非常大的垃圾值的内容。 Ex: 30K continues alphanumeric characters without any empty space.
例如:30K继续字母数字字符,没有任何空格。 In such cases, code take more very long time to process.
在这种情况下,代码将花费更多的时间。 Ex : more than a minutes , where normal content (without such junk content) takes less than a second .
例如: 超过一分钟 ,正常内容(不包含垃圾内容)的时间不到一秒钟 。
Couple of clarifications: 几个说明:
Not with regex. 不适用于正则表达式。
Find character '@' at line 在行中找到字符“ @”
int at = str.indexOf('@'); int = str.indexOf('@'); if(i == -1) return;
if(i == -1)返回; String address = str.substring(0, at - 1);
字符串地址= str.substring(0,at-1);
Find domain 查找域名
if(str.substring(at).indexOf('.') == -1) return; if(str.substring(at).indexOf('。')== -1)返回; String domain = str.substring(at + 1)
字符串域= str.substring(at + 1)
Validate for incorrect symbols 验证不正确的符号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.