0
点赞
收藏
分享

微信扫一扫

正则表达式(模拟网络爬虫、网络蜘蛛)


网络爬虫(网络蜘蛛)

    需求:获取邮箱

package com.cn.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Author:Liu Zhiyong
* Version:Version_1
* Date:
* Desc:
网络爬虫(网络蜘蛛)
*/
public class Demo4 {
public static void main(String[] args) {
String str = "qq 有事请联系";

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() );
}
}
}

举报

相关推荐

0 条评论