简体   繁体   English

必须在字符串中找到IP地址或IP地址模式

[英]Have to find IP address OR IP address pattern in string

I have a below and many more below like strings in list.. I have to extract the IP addresses only from each string. 我在列表中有一个以下和更多类似的字符串..我必须从每个字符串中提取IP地址。

"Below server have been decommissioned via # C180013538 & C180025327 request. “通过#C180013538和C180025327请求退出服务器下方。
Please remove any firewall rules associated with this server, So that the IP\\'s can be re-used in the future. 请删除与此服务器关联的所有防火墙规则,以便将来可以重用IP。 Please refer attachment for FW rules removal server details.", \\'Server Details :- \\', \\'ServerName IP Address\\', \\'CHIIUGA06RR 请参阅FW规则删除服务器详细信息的附件。“,\\'服务器详细信息: - \\',\\'ServerName IP Address \\',\\'CHIIUGA06RR
10.103.225.37\\', \\'CICCKDBP11VE 10.103.113.11\\', \\'CICCKDBP12VE 10.103.113.13\\ /" 10.103.225.37 \\',\\'CICCKDBP11VE 10.103.113.11 \\',\\'CICCKDBP12VE 10.103.113.13 \\ /“

Expected Result : - 10.103.225.37 10.103.113.11 10.103.113.13 预期成果: - 10.103.225.37 10.103.113.11 10.103.113.13

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)

See: Extract IP address from an html string (python) 请参阅: 从html字符串中提取IP地址(python)

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

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