我有一个在 ping 后获取输出的脚本,输出如下所示:
var input = "PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.065 ms
64 bytes from localhost (127.0.0.1): icmp_req=2 ttl=64 time=0.073 ms
64 bytes from localhost (127.0.0.1): icmp_req=3 ttl=64 time=0.065 ms
--- localhost ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.065/0.067/0.073/0.010 ms"
我首先尝试获取传输了多少数据包。所以我尝试了这个正则表达式: (\d+)*\spackets
基本上与“NUMBER 个数据包”相匹配,它似乎在这个网站上工作:http ://www.regular-expressions.info/javascriptexample.html但我无法复制它。
并且当使用正则表达式进行匹配时,它也会失败,如下所示:
"42 packets".match('(\d+)*\spackets');
有任何想法吗?