Skip to content

Instantly share code, notes, and snippets.

@Djexus
Created March 20, 2012 21:09
Show Gist options
  • Save Djexus/2141326 to your computer and use it in GitHub Desktop.
Save Djexus/2141326 to your computer and use it in GitHub Desktop.
Regex to parse server's messages
nickname = r'[\w\x5b-\x60\x7b-\x7d]+'
username = r'[-+~=^]?[^@\s]+'
hostname = r'(?:\w|\d)+(?:[-.=](?:\w|\d)+)*'
mask = r'([\w\x5b-\x60\x7b-\x7d]+)(?:(?:!([-+~=^]?[^@\s]+))?@((?:\w|\d)+(?:[-.=](?:\w|\d)+)*))?'
servername = r'(?:\w|\d)+(?:[-.](?:\w|\d)+)*'
prefix = r'[\w\x5b-\x60\x7b-\x7d]+(?:(?:![-+~=^]?[^@\s]+)?@(?:\w|\d)+(?:[-.=](?:\w|\d)+)*)?|(?:\w|\d)+(?:[-.](?:\w|\d)+)*'
command = r'[A-Z]+|[0-9]{3}'
parametres = r'[^:]+'
trailing = r':(.+)'
message = r'^(?::([\w\x5b-\x60\x7b-\x7d]+(?:(?:![-+~=^]?[^@\s]+)?@(?:\w|\d)+(?:[-.=](?:\w|\d)+)*)|(?:\w|\d)+(?:[-.](?:\w|\d)+)*)\s)?([A-Z]+|[0-9]{3})(?: ([^:]+))?(?: :(.+))?$'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment