Java 使用正则表达式从文件中解析出所有email地址,正则表达式email,package net.
分享于 点击 49813 次 点评:225
Java 使用正则表达式从文件中解析出所有email地址,正则表达式email,package net.
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[.-]]+\\\\.[\\\\w]+"); /** * @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://byrx.net
用户点评