import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Demo133 {
public static void main(String[] args) {
String str = " 有事没事联系:[email protected] 有事没事联系:[email protected] 有事没事联系:[email protected] "
+ "有事没事联系:[email protected] 有事没事联系:[email protected] 有事没事联系:[email protected] 有事没事联系:[email protected] 有事没事联系:[email protected] 有事没事联:[email protected] 有事没事联系:[email protected] 有事没事联系:[email protected]";
String reg = "[a-zA-Z1-9]\\w{1}[a-zA-Z0-9]\\w{1,10}@[a-zA-Z0-9]{2,}(\\.[a-z]{2,3}){1,2}";
//第一步: 先要把字符串的正则 编译成Pattern对象。
Pattern p = Pattern.compile(reg);
//第二步: 把正则对象匹配字符串对象得到一个匹配器
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}
JAVA小练习133——抓取邮件
猜你喜欢
转载自blog.csdn.net/Eric_The_Red/article/details/91972084
今日推荐
周排行