【发布时间】:2023-04-01 16:12:01
【问题描述】:
iplist.txt的内容是这样的格式:
CART 6385 Cell IP: 10.10.10.10
CART 3854 Cell IP: 10.10.10.10
CART 385 Cell IP: 10.10.10.10
我需要帮助获取下面的 python 脚本以仅匹配 385 并打印结果。
我的代码:
IPList = open('iplist.txt','r')
CartID = raw_input('What is the Cart ID? ')
for line in IPList:
if re.search(CartID, line):
print line.strip()
输出:
What is the Cart ID? 385
CART 6385 Cell IP: 10.10.10.10
CART 3854 Cell IP: 10.10.10.10
CART 385 Cell IP: 10.10.10.10
我只需要它匹配CART 385。
【问题讨论】:
标签: python variables pattern-matching