【问题标题】:Have to find IP address OR IP address pattern in string必须在字符串中找到 IP 地址或 IP 地址模式
【发布时间】:2019-08-25 05:10:23
【问题描述】:

我有一个下面和更多类似列表中的字符串。我必须只从每个字符串中提取 IP 地址。

“以下服务器已通过 #C180013538 & C180025327 请求停用。
请删除与此服务器关联的所有防火墙规则,以便将来可以重新使用 IP。 防火墙规则删除服务器详情请参考附件。", \'服务器详情:- \', \'ServerName IP Address\', \'CHIIUGA06RR
10.103.225.37\', \'CICCKDBP11VE 10.103.113.11\', \'CICCKDBP12VE 10.103.113.13\ /"

预期结果:- 10.103.225.37 10.103.113.11 10.103.113.13

【问题讨论】:

标签: regex python-3.x numbers ip-address


【解决方案1】:
import re

list = ["\'Server Details :- \', \'ServerName IP Address\', \'CHIIUGA06RR 10.103.225.37\', \'CICCKDBP11VE 10.103.113.11\', \'CICCKDBP12VE 10.103.113.13\ /", 
"\'Server Details :- \', \'ServerName IP Address\', \'CHIIUGA06RR 10.103.225.37\', \'CICCKDBP11VE 10.103.113.11\', \'CICCKDBP12VE 10.103.113.13\ /"]

for s in list:
    print re.findall( r'[0-9]+(?:\.[0-9]+){3}',  s)

见:Extract IP address from an html string (python)

【讨论】:

    猜你喜欢
    • 2018-01-22
    • 2015-06-22
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多