[英]regular expression for multiple IP address with different range, need to pharse specific IP
我正在尋找正則表達式來驗證不同掩碼的 IP 地址
例子:
IP = [10.0.1.1 , 192.168.1.1, 200.1.1.1]
在這些 IP 中,我只需要為10.0.1.1
解析(查找)IP。
嘗試使用此處找到的 python ip_address
庫( https://docs.python.org/3/library/ipaddress.html )
您可以嘗試做的是將它們全部解析為對象列表
result = list(map(ipaddress.ip_address, IP))
# then we filter depending on the bitmask here
您應該提供有關您在 IP 地址中查找哪種模式的更多信息?
根據您當前的需要,您可以使用它:
import re
pattern=r'\d{2}(?=[.]).\d{1}([.]\d{1})(\1)'
string="IP = [10.0.1.1 , 192.168.1.1, 200.1.1.1]"
match=re.search(pattern,string)
print(match.group())
輸出:
10.0.1.1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.