import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(^[a-zA-Z._-]+)\\(([0-9]+)\\) : (error.*)";
final String string = ".\\include\\intentionally_initally_empty.txt\n"
+ "1 File(s) copied\n\n"
+ "// Compiling galileo.sma ... Current time is: 15:26:16,93 - 11/09/2016\n\n"
+ "Welcome to the AMX Mod X 1.8.1-300 Compiler.\n"
+ "Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team\n\n"
+ "galileo.sma(1026) : error 017: undefined symbol \"nextmap_plugin_init\"\n"
+ "galileo.sma(1032) : error 017: undefined symbol \"register_dictionary_colored\"\n"
+ "galileo.sma(1208) : error 017: undefined symbol \"nomination_clearAll\"\n"
+ "gali_leo.sma(1288) : error 017: undefined symbol \"get_realplayersnum\"\n"
+ "galileo.sma(1455) : error 017: undefined symbol \"serverChangeLevel\"\n"
+ "galileo.sma(1524) : error 017: undefined symbol \"saveEndGameLimits\"\n"
+ "gali-leo.sma(1558) : error 017: undefined symbol \"map_getNext\"\n"
+ "galileo.sma(1572) : error 017: undefined symbol \"map_getNext\"\n"
+ "galileo.sma(1620) : error 017: undefined symbol \"saveCurrentMapCycleSetting\"\n"
+ "galileo.sma(2294) : error 017: undefined symbol \"cancelVoting\"\n"
+ "galileo.sma(2312) : error 017: undefined symbol \"cancelVoting\"\n"
+ "galileo.sma(2389) : error 017: undefined symbol \"map_getMinutesElapsedInteger\"\n"
+ "galileo.sma(2389) : error 017: undefined symbol \"saveEndGameLimits\"\n"
+ "galileo.sma(2390) : error 017: undefined symbol \"saveEndGameLimits\"\n"
+ "galileo.sma(2391) : error 017: undefined symbol \"saveEndGameLimits\"\n"
+ "galileo.sma(2392) : error 017: undefined symbol \"saveEndGameLimits\"\n"
+ "galileo.sma(2942) : error 017: undefined symbol \"get_realplayersnum\"\n"
+ "galileo.sma(2954) : error 017: undefined symbol \"get_realplayersnum\"\n"
+ "galileo.sma(3062) : error 017: undefined symbol \"get_realplayersnum\"\n"
+ "galileo.sma(3169) : error 017: undefined symbol \"map_isInMenu\"\n"
+ "galileo.sma(3352) : error 017: undefined symbol \"get_realplayersnum\"\n"
+ "galileo.sma(3425) : error 017: undefined symbol \"getPlayerNominationMapIndex\"\n"
+ "galileo.sma(3471) : error 017: undefined symbol \"get_realplayersnum\"\n"
+ "galileo.sma(3545) : error 017: undefined symbol \"color_print\"\n"
+ "galileo.sma(3551) : error 017: undefined symbol \"color_print\"\n"
+ "galileo.sma(3627) : error 017: undefined symbol \"color_print\"\n\n"
+ "Compilation aborted.\n"
+ "26 Errors.\n"
+ "Could not locate output file compiled/galileo.amx (compile failed).\n\n"
+ "Took 0:00:01,54 seconds to run this script.\n\n"
+ "[Finished in 2.3s]";
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