正则表达式,获取功能演示练习!!

1.指定需要操作的字符串数据
2.书写正则表达式
3.将正则表达式转成正则对象
4.将字符串和正则对象进行组合
5.使用匹配器获取正则匹配上的数据内容(find(),group())

import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
 * 获取功能
 */
public class Demo03 {
	public static void main(String[] args) {
		String s = "dasfsd18995131310fdsfkgtritp15719318798fdskfldsfafk";
		String regex="1[34578]\\d{9}";
		Pattern s2 = Pattern.compile(regex);
		Matcher s3 =s2.matcher(s);
		while(s3.find()) {
			System.out.println(s3.group());
		}
		
	}
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43117449/article/details/82778219