/**
获取满足条件的字串
*/
public static void main(String[] args) {
String str = "hao hao xue xi,tian tian xiang shang,ao li gei";
String regex = "\\b[a-zA-Z]{3}\\b";
//1、将正则规则进行对象封装
Pattern pat = Pattern.compile(regex);
//2、通过正则对象获取匹配器对象
Matcher mat = pat.matcher(str);
//3、查找
while (mat.find()) {
//4、获取当前子序列
System.out.println(mat.group());
}
}
正则表达式获取满足条件的字符串
最新推荐文章于 2022-08-09 20:17:53 发布