繁体   English   中英

使用Regex从ipconfig提取IP地址

[英]Extract IP address from ipconfig using Regex

在使用Regex运行ipconfig之后,我只想从下面的输出中提取IPv4地址。

    Connection-specific DNS Suffix  . : domain.local
    Link-local IPv6 Address . . . . . : fe80::49b6:17f6:f059:1c3d%12
    IPv4 Address. . . . . . . . . . . : 192.168.2.180
    Subnet Mask . . . . . . . . . . . : 255.255.255.0
    Default Gateway . . . . . . . . . : 192.168.2.254

因此,我只想提取“ 192.168.2.180”地址。

^ *IPv4 Address[.\\s]*:\\s*([\\d.]+)\\s*$

它不会对IP地址进行任何完整性检查。

有更好的解析IP地址的方法,但是这种方法很简单,仅能捕获您需要的内容:

http://rubular.com/r/PxEX4Lk56w

\\s+IPv4 Address.*: ([\\d\\.]+)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM