1 package com.wy.regular; 2 3 import java.io.BufferedReader; 4 import java.io.FileNotFoundException; 5 import java.io.FileReader; 6 import java.io.IOException; 7 import java.util.regex.Matcher; 8 import java.util.regex.Pattern; 9 10 public class RegularTest { 11 12 public static void main(String[] args) { 13 BufferedReader br = null; 14 try { 15 br= new BufferedReader(new FileReader("D:\xxx\正则表达式\2018919.html")); 16 String line = ""; 17 while ((line = br.readLine()) != null) { 18 parse(line); 19 } 20 } catch (FileNotFoundException e) { 21 e.printStackTrace(); 22 } catch (IOException e) { 23 e.printStackTrace(); 24 } 25 } 26 27 private static void parse(String line) { 28 Pattern pattern = Pattern.compile("[\w[.-]]+@[\w[.-]]+\.[\w]+"); 29 Matcher matcher = pattern.matcher(line); 30 while (matcher.find()) { 31 pri(matcher.group()); 32 } 33 } 34 35 public static void pri(Object object){ 36 System.out.println(object); 37 } 38 }
结果: