网络爬虫(网络蜘蛛)
需求:获取邮箱
package com.cn.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Author:Liu Zhiyong(QQ:1012421396)
* Version:Version_1
* Date:
* Desc:
网络爬虫(网络蜘蛛)
*/
public class Demo4 {
public static void main(String[] args) {
String str = "有事请联系:1012421396@qq.com 有事请联系:396@qq.com 有事请联系:1012421396@qq.com.cn 有事请联系:1012421396@qq.net 有事请联系:1012421396@qq.cn 有事请联系:1012421396@163.com";
String regex = "[a-zA-Z1-9]\\w{5,17}@[a-zA-Z0-9]{2,}(\\.(com|cn|net)){1,2}";
//把字符串的正则编译成正则对象
Pattern p = Pattern.compile(regex);
//使用正则对象产生匹配器对象
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group() );
}
}
}