Reputation: 1564
I am trying to match all "ALL ZEROs" from the following command output.
router-7F2C13#show app stats gmail on TEST/switch1234-15E8CC
--------------------------------------------------------------------------------
APPLICATION BYTES_IN BYTES_OUT NUM_FLOWS
--------------------------------------------------------------------------------
gmail 0 0 0
--------------------------------------------------------------------------------
router-7F2C13#
I need to meet the following requirements:
I tried with following code:
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)
But its throws following error:
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>
Can anyone please help me to fix this?
Is it possible to match only all zero's with exact spaces?
Upvotes: 0
Views: 100
Reputation: 9647
You might try a regex like
\s*\w+\s+(\d+)\s+(\d+)\s+(\d+)
This would seem to match
gmail 0 0 0
An alternative (at your request) is to match the literal 0
's. Just replace the digit match with 0:
\s*\w+\s+(0)\s+(0)\s+(0)
Note that the (parentheses) are for grouping, and may not be necessary depending on how you'll be using the regex. If you're just testing for a match, you can drop them.
Then you should probably write a function to ensure the matches are all 0.
You might take a look at debuggex.
Upvotes: 1