展开全部
用正则表达式提取一个网站里面的所有邮箱地址e68a8462616964757a686964616f31333337616565
importjava.io.BufferedReader;
importjava.io.FileReader;
importjava.io.IOException;
importjava.util.regex.*;
publicclassMyRegex{
publicstaticvoidmain(String[]args){
try{
//读取网页文件,里面有N个邮箱地址
Stringcontent=read("e:/1.htm");//read()方法在下面
//匹配邮箱的正则表达式
Stringregex="//w+([-+.']//w+)*@//w+([-.]//w+)*//.//w+([-.]//w+)*";
Matcherm=pile(regex).matcher(content);
while(m.find()){
//输出邮箱地址
System.out.println(m.group());
}
}catch(IOExceptione){
e.printStackTrace();
}
}
/**
*读取文本内容
*@paramfileName文本名称,包括路径
*@return返回文本内容
*/
publicstaticStringread(StringfileName)throwsIOException{
BufferedReaderbr=newBufferedReader(newFileReader(fileName));
StringBuildersb=newStringBuilder();
Strings;
while((s=br.readLine())!=null)
{
sb.append(s);
sb.append("/r/n");
}
br.close();
returnsb.toString();
}
}
如果觉得《java 正则提取邮箱_如何用正则表达式提取一个网站里面的所有邮箱地址?》对你有帮助,请点赞、收藏,并留下你的观点哦!