我正在尝试从ping结果中读取值,就像我想使用正则表达式将Received value读取为4或Lost值为0。
Ping statistics for 74.125.200.94:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 63ms, Maximum = 64ms, Average = 63ms
我正在尝试以下,但没有去,任何帮助?
$test = ping google.co.in
$test -match "^Average = \((\d+)\)$"
答案 0 :(得分:1)
只需使用[regex]::Match
来获取信息:
$test = ping google.co.in
$match = [regex]::Match($test, 'Received = (\d+), Lost = (\d+)')
$received = $match.Groups[1].Value
$lost = $match.Groups[2].Value