import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\[(?<time>(?:[\\d]+\\:[\\d]+:[\\d]+)\\s+(?:AM|PM))(?:\\s+\\|\\s+\\w+\\s+(?<edited>(?:[\\d]+\\:[\\d]+:[\\d]+)\\s+(?:AM|PM)))?\\]\\s+(?<author>\\w+)\\:\\s+(?<message>[\\w\\s,.]+)";
final String string = "[9:14:51 AM] Jeff: If you could just do me a favoure and list all these concerns and in a mail and if you have any ideas that you might want to implement so that I can get everybodys notes.\n"
+ "[9:14:56 AM] Timmy: in terms of websites or domains or DNSs I have no clue about setup\n"
+ "[9:15:19 AM | Edited 9:15:25 AM] Jeff: That, I will get Sam and Frodo involved in\n"
+ "[9:16:01 AM] Jeff: I am stepping out quickly";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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