簡體   English   中英

Grep ping輸出僅使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM