我有这个字符串列表:
['config firewall vip\n', ' edit "VIP"\n', ' config realservers\n', ' edit 1\n', ' set ip \n', ' next\n', ' end\n', ' next\n', 'end\n']
然后我有以下python代码:
posIni = confCompleta.index('config firewall vip\n')
posFim = confCompleta.index('end\n',posIni) + 1
blocoVip = []
m = 0
for n in range (posIni,posFim):
blocoVip.insert(m,confCompleta[n])
m = m + 1
indiceInicialVip = [i for i, s in enumerate(blocoVip) if ' edit ' in s]
indiceFinalVip = [i for i, s in enumerate(blocoVip) if ' next\n' in s]
我不希望posFim匹配第一个“end”,因为之前有空格。出于同样的原因,'edit 1'也应该在'indiceInicialVip'中不匹配,因为它之前有超过4个空格。我如何告诉python不要忽略那些空格?我想匹配整条线。