正则表达式爬取信息
package RegularExpression.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* FileName: Regextest5
* Author: lps
* Date: 2022/4/13 14:50
* Sign:刘品水 Q:1944900433
*/
public class Regextest5 {
public static void main(String[] args) {
String rs="qwertyui0511-157514033qwertdasdasudyfsfdfsdfsgfgdg" +
"bfdbvxvxvxcvvcxvda" +
"fdaf!1944900433@qq.com,dasdasdadasd15751403365das400-123456-123456";
//从上面找出电话号码和邮箱
String regex="\\w{1,30}@[a-zA-Z0-9]{2,20}(\\.[a-zA-Z0-9]{2,20}){1,2}|1[3-9]\\d{9}|" +
"0\\d{2,6}-?\\d{5,20}|(400-?\\d{3,9}-?\\d{3,9})";
//把这些爬取规则编译成匹配对象
Pattern pattern=Pattern.compile(regex);
//得到一个内容 匹配对象
Matcher matcher = pattern.matcher(rs);
//开始爬
while (matcher.find()){
String rs1=matcher.group();
System.out.println(rs1);
}
}
}