import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(.*)(\\s<name.*)";
final String string = "2016-07-01 02:50:35 <name redacted> hey\n"
+ "2016-07-01 02:51:26 <name redacted> waiting for plane to Edinburgh\n"
+ "2016-07-01 02:51:45 <name redacted> thinking about my boo\n"
+ "2016-07-01 02:52:07 <name reda> nothing crappy has happened, not really\n"
+ "2016-07-01 02:52:20 <name redac> plane went by pretty fast, didn't sleep\n"
+ "2016-07-01 02:54:08 <name r> no idea what time it is or where I am really\n"
+ "2016-07-01 02:54:17 <name redacted> just know it's london\n"
+ "2016-07-01 02:56:44 <name redacted> you are probably asleep\n"
+ "2016-07-01 02:58:45 <name redacted> I hope fish was fishy in a good eay\n"
+ "2016-07-01 02:58:56 <name redacted> 💘\n"
+ "2016-07-01 02:59:34 <name redacted> 🍑🍑🍑\n"
+ "2016-07-01 03:02:48 <name > British security is a little more rigorous...";
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