(一)校验Email //校验email public static void regEmail(){ String email = "zhoujian@sina.com"; boolean b = email.matches("\\w+@\\w+(\\.\\w+){1,3}"); System.out.println(b); //true } (二)网页爬虫//网页爬虫 public static void inteCrawler() throws IOException{ //网页爬虫:是在互联网上查找需要信息的程序,例如:爬邮箱 //1. 读取的信息 URL url = new URL("http://www.sina.com.cn"); BufferedReader bfr = new BufferedReader(new InputStreamReader(url.openStream())); //2. 对读取的信息进行匹配,从中获取需要的信息 String reg = "\\w+@\\w+(\\.\\w+)+"; Pattern p = Pattern.compile(reg); //3. 将符合条件的信息集中存储 List<String> list = new ArrayList<String>(); String line = null; while((line = bfr.readLine())!=null){ Matcher m = p.matcher(line); while(m.find()){ list.add(m.group()); } } System.out.println(list); }
|