下面的代码更改应该可以做到这一点。
match = re.match(r'input\s+(.*)\s*(.*)',lines[i], re.M|re.I) if (match): matches = list(match.groups()) if '' in matches: matches.remove('') print matches[-1] else: print 'nomatch'
“\s”字符序列与空白匹配。 This 是正则表达式的好教程。