正则表达式:提取以数字开头,以点结尾的字符串

前端之家收集整理的这篇文章主要介绍了正则表达式:提取以数字开头,以点结尾的字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

关于正则表达式的一些规则,可以参考jdkAPI文档。

  1. @Test
  2. public void test3(){
  3. String str = "正则调用顺序:1.Pattern p = Pattern.compile('a*b'); 2.Matcher m = p.matcher('aaaaab'); 3.boolean b = m.matches();";
  4. String regex = "\\d+\\.";
  5. Pattern p = Pattern.compile(regex);//将给定的正则表达式编译到模式中。
  6. Matcher m = p.matcher(str);//创建匹配给定输入与此模式的匹配器。
  7. while(m.find()){
  8. System.out.println(m.group());
  9. }
  10. }

运行结果:

  1. 1.
  2. 2.
  3. 3.

猜你在找的正则表达式相关文章