Created
September 7, 2011 19:07
-
-
Save uranusjr/1201421 to your computer and use it in GitHub Desktop.
Verbose Python RegExp Match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pattern = re.compile(r''' | |
\d{4}\-\d{2}\-\d{2} # yyyy-mm-dd | |
\s | |
\d{2}:\d{2}:\d{2} # HH:mm:ss | |
\s | |
(\d{1,3}\.){3}\d{1,3} # IP | |
\(via\sUDP:\s\[ | |
(\d{1,3}\.){3}\d{1,3} # UDP IP | |
\]: | |
\d+ # UDP port? | |
\)\sTRAP,\sSNMP\sv1,\scommunity\spublic\n\s+SNMPv2-SMI::enterprises.2604. | |
\d.\d.\d.\d # COMMENT ME | |
\sEnterprise\sSpecific\sTrap\s\( | |
\w+ # COMMENT ME | |
\)\sUptime:\s | |
(\w+\sdays,)* # Uptime, day part (may not exist) | |
\d+:\d+:\d+.\d+ # Uptime, hh:mm:ss.xx | |
\n\s+SNMPv2-SMI::enterprises.2604. | |
\d.\d.\d.\d.\d.\d # COMMENT ME | |
\s=\sHex-STRING:\s | |
(\w+\s)+ # Hex STRING | |
\s+SNMPv2-SMI::enterprises.2604. | |
\d.\d.\d.\d.\d.\d # COMMENT ME | |
\s=\sSTRING:\s\" | |
.+ # content of STRING | |
\" | |
''', re.VERBOSE) | |
print pattern.match(content) # "content" is the string to match |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment