我想從以下命令輸出中匹配所有「所有ZERO」。如何準確使用python正則表達式匹配「0 0 0」?
router-7F2C13#show app stats gmail on TEST/switch1234-15E8CC
--------------------------------------------------------------------------------
APPLICATION BYTES_IN BYTES_OUT NUM_FLOWS
--------------------------------------------------------------------------------
gmail 0 0 0
--------------------------------------------------------------------------------
router-7F2C13#
我需要滿足以下要求:
我用下面的代碼嘗試:
x="""router-7F2C13#show app stats gmail on TEST/switch1234-15E8CC
--------------------------------------------------------------------------------
APPLICATION BYTES_IN BYTES_OUT NUM_FLOWS
--------------------------------------------------------------------------------
gmail 0 0 0
--------------------------------------------------------------------------------
router-7F2C13#"""
def pass_fail_criteria(x):
if int(re.findall(r"NUM_FLOWS\n-+[\s\S]*?(\d+)\s*-+"):
print "FAIL"
else:
print "PASS"
print pass_fail_criteria(x)
但它會引發以下錯誤:
C:\Users\test\Desktop>python test_regexp.py
File "test_regexp.py", line 17
if int(re.findall(r"NUM_FLOWS\n-+[\s\S]*?(\d+)\s*-+"):
^
SyntaxError: invalid syntax
C:\Users\test\Desktop>
誰能幫我解決這個問題?
是否有可能匹配所有零與確切的空格?
有兩個問題,在這裏...答案第一個是...關閉**支架! – 2015-02-05 16:34:53