ITeye博客

网页中提取email

wysaijun1314 · 2012-10-24 16:48 · java · web · 正则表达式 · 编程语言 · Markdown

从百度上找出的一用正则提取网页中email的例子,供自己和大家参考


URL url = new URL("l"); //网页地址 
	        // 打开连接  
	        URLConnection conn = url.openConnection();  
	        // 设置连接网络超时时间  
	        conn.setConnectTimeout(1000 * 10);  
	        // 读取指定网络地址中的文件  
	        BufferedReader bufr = new BufferedReader(new InputStreamReader(conn.getInputStream()));  
	        String line = null;  
	        String regex = "[a-za-z0-9_-]+@\\w+\\.[a-z]+(\\.[a-z]+)?";  // email的正则  
	        Pattern p = Pattern.compile(regex);  
	        while((line = bufr.readLine()) != null) {  
	            Matcher m = p.matcher(line);  
	            while(m.find()) {  
	                System.out.println(m.group());    // 输出匹配的email  
	            }  
	        }  

从文本文件中提取email例子

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。