正则表达式的验证:

1.使用Pattern预编译字符串

2.调用Matcher的对象

3.使用该Matcher对象的matches方法来返回boolean类型的值(符合为true,不符合为false)

 

                String str = "123abcd";

		String exg= "^//d$";//判断是否符合数字类型

		Pattern p = Pattern.compile(exg);//完成预编译正则

		Matcher m = p.matcher(str );//进行匹配字符串

		boolean matches = m.matches();//返回匹配的结果
		
		
                //简写为如下
		boolean m1 = Pattern.compile(str).matcher(a).matches();

  

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2021-11-25
  • 2022-01-24
  • 2022-02-13
  • 2021-12-29
  • 2021-12-22
猜你喜欢
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案