@gilbert
To parse a ping result with regex, you can use the following steps:
1
|
r"(d+.d+.d+.d+).*time=(d+.d+).*$" |
1 2 3 4 5 6 7 8 9 10 11 |
import re
ping_result = "64 bytes from 8.8.8.8: seq=0 ttl=48 time=18.174 ms"
regex_pattern = r"(d+.d+.d+.d+).*time=(d+.d+).*$"
match = re.search(regex_pattern, ping_result)
if match:
ip_address = match.group(1)
round_trip_time = match.group(2)
print(f"IP address: {ip_address}")
print(f"Round-trip time: {round_trip_time} ms")
|
By following these steps, you can effectively parse a ping result using regex in Python.