您的位置:首页 > 编程语言 > Java开发

使用java正则表达式提取文本中所有邮箱地址

2014-09-14 22:23 686 查看
package net.oschina.tester;

import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;

/**
* 提取邮件地址
* @author Winter Lau
* @date 2010-6-14 下午04:56:15
*/
public class EmailParser {

private final static Pattern emailer = Pattern.compile("\\w+?@\\w+?.com");

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String txt = FileUtils.readFileToString(new File(args[0]));
//System.out.println(txt);
Matcher matchr = emailer.matcher(txt);
while (matchr.find()) {
String email = matchr.group();
System.out.println(email);
}
}

}


转自:http://www.oschina.net/code/snippet_12_544
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: