如何识别列表中的主导电子邮件模式

时间:2015-07-09 22:43:04

标签: java regex

这是可能的,例如:

jon.smith@abc.com
henry.smith@abc.com 
brian.smith@abc.com
jons@abc.com
john@abc.comenter 

是一个域的电子邮件ID 例如,主导的模式是first.last name。

有没有办法以excel或任何其他方式识别电子邮件列表中的主导模式? 这只适用于一家公司abc

如果有十个域名,每个域名包含五封电子邮件,那么我应该能够从这些电子邮件中找到五种主导格式。

想知道是否有人可以帮我开始搜索并找到自动化方法。

1 个答案:

答案 0 :(得分:0)

似乎您正在使用正则表达式对字符串进行分类。这使用正则表达式来匹配@符号前面包含文字点(。)的表达式。我修改了tutorialspoint中的一些代码以适应电子邮件模式。

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches {
    public static void main(String args[]){

          // String to be scanned to find the pattern.
          String[] emails = {"jon.smith@abc.com", "jonsmith@abc.com"};
          String pattern = "\\w+[.]\\w+(?=@)";

          // Create a Pattern object
          Pattern r = Pattern.compile(pattern);


    for (int i=0; i<emails.length; i++) {
    // Now create matcher object.
    String line = emails[i];
    System.out.println(line);
          Matcher m = r.matcher(line);
          if (m.find()) {
             System.out.println("MATCH");
          } else {
             System.out.println("NO MATCH");
          }
    }
       }
    }
相关问题