![](/img/trans.png)
[英]How to avail a multiple link latency check and show the ping result, then have the fastest URL picked out using JavaScript?
[英]Grep ping output to only show latency using javascript
由此:
PING google.com (74.125.68.138) 56(84) bytes of data.
64 bytes from sc-in-f138.1e100.net (74.125.68.138): icmp_seq=1 ttl=48 time=76.8 ms
64 bytes from sc-in-f138.1e100.net (74.125.68.138): icmp_seq=2 ttl=48 time=86.8 ms
我需要使用javascript分隔此部分:
76.8
86.8
到目前為止,我想到了這個:
'([0-9][0-9][0-9].[0-9] ms|[0-9][0-9].[0-9] ms|[0-9].[0-9] ms)'
但是當延遲超過2位數時,它似乎無法正常工作。
您可以使用:
/time=(\d+(\.\d+)?) ms$/ // 1: one digit or more
\_/\______/ // 2: optionally followed by a dot and one digit or more
1 2 // $: end of input
var ping = "64 bytes from sc-in-f138.1e100.net (74.125.68.138): icmp_seq=1 ttl=48 time=76.8 ms"; var time = Number(ping.match(/time=(\\d+(\\.\\d+)?) ms$/)[1]); console.log(time);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.