For循环如果 - 即使字符串存在,也不匹配字符串

时间:2017-06-16 08:46:02

标签: string python-2.7 matching

以下代码在所有if语句中都不匹配 我想知道是什么使得if语句在第二个for循环中匹配,而不是在第一个和第三个for循环中?

for line in x:
    if '0.0.0.0/0' and 'A' in line:
        y = re.findall(r'\b\d{2,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', str(line))

这些是x中的行 没有行匹配,但正确的值仍然会进入y,因为它是唯一匹配正则表达式的行 0 ADS 0.0.0.0/0 41.222.225.255 0
1 ADC 41.222.225.255/32 197.242.206.100 pppoe-out1 0
2 ADC 172.20.0.0/24 172.20.0.1 LAN 0

gw = []
for line in x:
        if y and '/32' in line:
        gw.append(str(line).split()[4])

x中的行与预期匹配。
我没有显示其他没有匹配的线路  1 ADC 41.222.225.255/32 197.242.206.100 pppoe-out1 0

mtu = []
for line in x:
    print line
    if str(gw) in line:
        mtu.append(re.findall(r'actual-mtu=\d{1,4}\s*', str(x)))

x中没有匹配的行。
13 R name = pppoe-out1 type = pppoe-out mtu = 1480 actual-mtu = 1480 fast-path = yes last-link-down-time = jun / 15/2017 20:37:43 last-link-up-time = jun / 15/2017 20:37:44 link-downs = 11

0 个答案:

没有答案