Advertisement
zephyrtronium

rfc1459 regex

Feb 4th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # This should be (mostly) RFC-compliant and is designed to allow for quick and
  2. # easy extraction of parameters. It does not allow an @ in the username, which
  3. # is allowed by the RFC (but probably no IRCds).
  4. # This pattern consumed several hours of my time. I had fun.
  5. message_re = re.compile(
  6.     r'^(?P<message>' # This is really just to have it there.
  7.     r'(?::(?P<sender>(?P<nick>[][a-zA-Z0-9_\\`{}^|-]+)' # nick
  8.     r'(?:!(?P<user>[^\0\n\r @]+))?' # user
  9.     r'(?:@(?P<host>[a-zA-Z0-9.-]+|' # host (next line is ipv6 address)
  10.     r'(?:[0-9a-f]{0,4}:)+(?:(?:(?:\d{1,3}\.){3}\d{1,3})|[0-9a-f]{1,4})?))?|'
  11.     r'(?P<server>[a-zA-Z0-9.-]+)) +)?' # server
  12.     r'(?:(?P<command>[a-zA-Z]+)|' # command
  13.     r'(?P<response>\d{3}))' # response
  14.     r'(?: +(?P<params>(?P<middle>(?:(?!:)[^\0\n\r ]+ *?)*) *' # middle
  15.     r'(?::(?P<trailing>[^\0\n\r]*))?))?)$' # trailing
  16.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement