Skip to content

Instantly share code, notes, and snippets.

@yaronv
Last active July 31, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronv/6eec11cb1fb3efc79c0b508f03f13bd4 to your computer and use it in GitHub Desktop.
Save yaronv/6eec11cb1fb3efc79c0b508f03f13bd4 to your computer and use it in GitHub Desktop.
def ismessage(self, str):
patterns = {
"pattern1":r'(\d{1,2}/\d{1,2}/\d{2,4}),\s+(\d{2}:\d{2})\s*-\s*(\w*\s*\w*)\s*:\s*(.*)'
}
for key in patterns:
r = re.search(patterns[key], str)
if r != None:
date = r.group(1)
time = r.group(2)
name = r.group(3).lower()
message = r.group(4).translate(str.maketrans('','',string.punctuation))
return [date, time, name, message]
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment