String regex = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-){1,}\\){1,3}[a-zA-z\\-]{1,}";
String html = "<sadasda>admin@xuwangcom<dasda><dsadsa>xuww@sscn<dsada>sdasda<>sdasdasd>xuwang@uistv<sasa>xuwang@sscn";//网页源码
Map<String,List<String>> mails = new HashMap<String, List<String>>();
Pattern pattern = Patterncompile(regex);
Matcher matcher = patternmatcher(html );//匹配类
String mail = null;
String url = null;
while (matcherfind()) {
mail = matchergroup();
url = mailsubstring(mailindexOf('@'));
if (mailsget(url) == null) {
mailsput(url, new ArrayList<String>());
}
mailsget(url)add(mail);
}
List<String> allMails = new ArrayList<String>();
for (List<String> list:mailsvalues()) {
allMailsaddAll(list);
}
for (String s:allMails) {
Systemoutprintln(s);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)