Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java正则表达式模式查询_Java_Regex_Find_Matcher - Fatal编程技术网

Java正则表达式模式查询

Java正则表达式模式查询,java,regex,find,matcher,Java,Regex,Find,Matcher,只是一个关于Java正则表达式模式的快速问题!所以说如果我有一个像..这样的方法 public void example() { Pattern p = Pattern.compile("\\d*"); Matcher m = p.matcher("ab34ef"); boolean b = false; while (b = m.find()) { System.out.println(m.start

只是一个关于Java正则表达式模式的快速问题!所以说如果我有一个像..这样的方法

    public void example()
    {
      Pattern p = Pattern.compile("\\d*");
      Matcher m = p.matcher("ab34ef");
      boolean b = false;
      while (b = m.find()) 
      {
        System.out.println(m.start() + " " + m.group()); 
      }
    }
如果我运行这个,我将得到以下输出

     0
     1
     2 34
     4
     5
     6

我知道这是怎么回事,除了它是如何在6点结束的,我想它会在5点结束。有人能给我解释一下吗?谢谢

在字符串中,
“ab34ef”
,有7个值为
的“空字符”。它们位于每个普通字符之间。它尝试从每个空字符开始查找匹配项,而不是从每个普通字符开始;i、 e.每个
在下面的位置:
“|a | b | 3 | 4 | e | f |”

6用于结尾的空字符。顺便说一句,您的
b
是完全多余的。你从来没读过。啊!知道了!明亮的谢谢!:)@用户3087397没问题。很高兴我能帮忙!