array = ['GW-date45:ger-date45:mySAPgives','DC-date48ccc:date48:mySAP']
# REGEX
hostname = []
for node in array:
hostname.append(re.findall(r'^[^-]*\K-([^:]+)', node))
for line in hostname:
print(line)
import re
array = ['GW-date45:ger-date45:mySAPgives','DC-date48ccc:date48:mySAP']
hostname = []
for node in array:
m = re.search(r'^[^-]*-([^:]+)', node)
if m:
hostname.append(m.group(1))
for line in hostname:
print(line)
Python} construct
re
不支持^{似乎您甚至不需要它,因为您只需要捕获组1的值。使用
参见Python demo。输出:
相关问题 更多 >
编程相关推荐