为什么我在java中的一个Matcher.find()执行中获得所有匹配?

为什么我在java中的一个Matcher.find()执行中获得所有匹配?,java,regex,string,Java,Regex,String,我的输入字符串是 “PING www.abc.com(172.217.160.132)56(84)字节的数据 maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=1 ttl=51时间=50.9毫秒 maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=2 ttl=51时间=67.0毫秒 maa03s29-in-f4.1e100.net(172.217.160.132)中的

我的输入字符串是

“PING www.abc.com(172.217.160.132)56(84)字节的数据

maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=1 ttl=51时间=50.9毫秒

maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=2 ttl=51时间=67.0毫秒

maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=3 ttl=51时间=81.6毫秒

---www.google.com ping统计数据--- 传输3个数据包,接收3个,0%数据包丢失,时间为2002ms rtt最小值/平均值/最大值/mdev=50.995/66.591/81.693/12.537 ms”

我的模式是

(\\d+字节自[\\w\\w]+\\(\\d+(\\.\\d+{3,3}\):icmp\u seq=\\d+ttl=\\d+时间=[\\d+.]+ms)

我执行

       int count++;
      while(matcher.find()) {
        count++;
System.out.print(count+" ");}
我的预期产出
123
但我的实际产出
1
当我尝试在while循环中打印matcher.group时

maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=1 ttl=51时间=50.9毫秒

maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=2 ttl=51时间=67.0毫秒

maa03s29-in-f4.1e100.net(172.217.160.132)中的64个字节:icmp_seq=3 ttl=51时间=81.6毫秒


为什么它会在第一次执行时找到所有匹配项?

[\\w\\w]+
替换为
+

(\\d+ bytes from .+ \\(\\d+(\\.\\d+){3,3}\\): icmp_seq=\\d+ ttl=\\d+ time=[\\d+.]+ ms)
#                ^^
  • [\\w\\w]+
    代表任何字符(包括换行符),贪婪(它匹配的字符最多),从第一个
    到最后一个
    (172…)
  • +
    匹配任何字符但换行符

[\\w\\w]+
替换为
+
是。成功了。你能告诉我它是如何工作的,我犯了什么错误吗?非常感谢