import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?P<datetime>\\d{2}\\/\\d{2}\\/\\d{4},\\s\\d(?:\\d)?:\\d{2} [pa].m.)\\s-\\s(?P<name>[^:]*):(?P<message>.*)";
final String string = "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: πππππΌππΌππΌ";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html