簡體   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