import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\[([^\\].]*)\\]:\\W?(.*)";
final String string = "[12:17:05][econ]: cid=0 authed\n"
+ "[12:17:11][server]: player is ready. ClientID=0 addr=87.100.133.110:64762\n"
+ "[12:17:11][game]: Teams are balanced (red=1 blue=0)\n"
+ "[12:17:11][server]: player has entered the game. ClientID=0 addr=87.100.133.110:64762\n"
+ "[12:17:11][game]: team_join player='0:wavi' team=0\n"
+ "[12:17:13][game]: pickup player='0:wavi' item=3\n"
+ "[12:17:25][game]: pickup player='0:wavi' item=2\n"
+ "[12:17:33][game]: flag_grab player='0:wavi' team=0\n"
+ "[12:17:34][game]: pickup player='0:wavi' item=1\n"
+ "[12:17:34][game]: pickup player='0:wavi' item=1\n"
+ "[12:17:43][game]: pickup player='0:wavi' item=0\n"
+ "[12:17:44][game]: flag_capture player='0:wavi' team=0 time=11.38\n"
+ "[12:17:48][game]: kill killer='0:0:wavi' victim='0:0:wavi' weapon=-1 special=0\n"
+ "[12:17:52][server]: client dropped. cid=0 addr=87.100.133.110:64762 reason=''\n"
+ "[12:17:52][game]: kill killer='0:0:wavi' victim='0:0:wavi' weapon=-3 special=0\n"
+ "[12:17:52][game]: leave player='0:wavi'\n"
+ "[12:17:52][game]: Teams are balanced (red=0 blue=0)\n\n\n"
+ "[econ]: cid=0 authed\n"
+ "[server]: player is ready. ClientID=0 addr=87.100.133.110:64762\n"
+ "[game]: Teams are balanced (red=1 blue=0)\n"
+ "[server]: player has entered the game. ClientID=0 addr=87.100.133.110:64762\n"
+ "[game]: team_join player='0:wavi' team=0\n"
+ "[game]: pickup player='0:wavi' item=1\n"
+ "[game]: pickup player='0:wavi' item=1\n"
+ "[game]: pickup player='0:wavi' item=1\n"
+ "[game]: pickup player='0:wavi' item=2\n"
+ "[game]: pickup player='0:wavi' item=4\n"
+ "[game]: flag_grab player='0:wavi'\n"
+ "[game]: pickup player='0:wavi' item=2\n"
+ "[game]: pickup player='0:wavi' item=0\n"
+ "[game]: pickup player='0:wavi' item=3\n"
+ "[game]: flag_capture player='0:wavi'\n"
+ "[game]: pickup player='0:wavi' item=2\n"
+ "[game]: kill killer='0:wavi' victim='0:wavi' weapon=-1 special=0\n"
+ "[server]: client dropped. cid=0 addr=87.100.133.110:64762 reason=''\n"
+ "[game]: leave player='0:wavi'\n"
+ "[game]: Teams are balanced (red=0 blue=0)";
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