# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?P<datetime>\d{2}\/\d{2}\/\d{4},\s\d(?:\d)?:\d{2} [pa].m.)\s-\s(?P<name>[^:]*):(?P<message>.*)"
test_str = ("15/11/2017, 10:59 p.m. - βͺSome random nameβ¬: Thats sounds like crow who don't know marathiπ€£\n"
"15/11/2017, 11:00 p.m. - Pratik: ππ\n"
"15/11/2017, 11:00 p.m. - Dhiraj Kadam: Msging language bruhπππ\n"
"15/11/2017, 11:00 p.m. - Rushiraj Msc: ππππ\n"
"15/11/2017, 11:00 p.m. - Shreyas : π©π©π©\n"
"15/11/2017, 11:01 p.m. - Abhisek Joshi: ππ\n"
"15/11/2017, 11:01 p.m. - βͺSome Name: Age piche ke students 2 ... 2 subject padho and copy.. nahi ata to thoko bhindhass\n"
"15/11/2017, 11:01 p.m. - Shreyas : ππΌππΌππΌππΌπ―\n"
"15/11/2017, 11:02 p.m. - βͺSome name: Respect the term autonomous\n"
"15/11/2017, 11:02 p.m. - βͺSome Name : Gharguti ...π
\n"
"14/11/2017, 9:54 a.m. - Abhisek Josh: πππ\n"
"14/11/2017, 10:37 a.m. - βͺSOme Name: Do you still remember those awkward days in schools during Exams ?\n\n"
"When a bright student tells the invigilator that question 4 has a problem, but you have already answered it...π³π\n\n"
"When a fellow student asks for a graph paper, but you are finished and did not see anywhere where it was required...π§ ππ\n\n"
"When the invigilator says jump question 6 we will rectify it later, but it was the question you enjoyed most when answering...π π±π²\n\n"
"When you see people busy using rulers and you are wondering what is going on...π£π«π«\n\n"
"When you hear your friends arguing after the exam whether the answer to question 5 was 35.5% or 36.5% and your answer was 1800 π©π\n\n"
"The cream. When the other students asked for 4-5 additional answer sheets and You had two pages empty in the main answer sheetπ¨π°π±\n\n"
"See where you have reached in life inspite of those moments...things are not permanent...enjoy life! ππ\n\n"
"Only for those who enjoyed their school lifeπππ\n\n"
"Top 10 Dialogue of teacher\n"
"π If you are not interested then you may leave the class.\n"
"π This class is worse than a fish market.\n"
"π Are you here to waste your parents money? \n"
"π Tell me when you all have finished talking.\n"
"π Why are u laughing? Come here n tell us we'll also laugh. \n"
"π Do you think teachers are fools to teach you?\n"
"π Don't try to act oversmart with me.\n"
"π Why do u come to school when you don't want to study.\n"
"π The previous batch was 100 times better than yours.\n"
"π If you want to talk then u may get out from the class.\n\n"
"And the best one\n"
"π You yes you... I am talking to you only, don't look back.. ππ\n"
".\n"
".\n"
".\n"
"I'm sure that the last line made all of you remember and smile .\n"
"14/11/2017, 10:42 a.m. - βͺNameβ¬: πππ\n"
"14/11/2017, 11:15 a.m. - Sanesh Sagvekar: Whos in clg now\n"
"14/11/2017, 11:15 a.m. - Sanesh Sagvekar: πππππΌππΌππΌ")
matches = re.finditer(regex, test_str)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html