欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java 使用正则表达式从文件中解析出所有email地址,正则表达式email,package net.

来源: javaer 分享于  点击 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
相关栏目:

用户点评