java如何找出一个网页内的所有电子邮箱并按邮箱服务器排序,可以给代码看下嘛 20
1个回答
展开全部
public static void main (String [] args) {
String regex = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
String html = "<sadasda>admin@xuwang.com<dasda><dsadsa>xuww@ss.cn<dsada>sdasda<>sdasdasd>xuwang@uis.tv<sasa>xuwang@ss.cn";//网页源码
Map<String,List<String>> mails = new HashMap<String, List<String>>();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(html );//匹配类
String mail = null;
String url = null;
while (matcher.find()) {
mail = matcher.group();
url = mail.substring(mail.indexOf('@'));
if (mails.get(url) == null) {
mails.put(url, new ArrayList<String>());
}
mails.get(url).add(mail);
}
List<String> allMails = new ArrayList<String>();
for (List<String> list:mails.values()) {
allMails.addAll(list);
}
for (String s:allMails) {
System.out.println(s);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询