import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "modified:\\s+((?>\\w+\\/?)+)[^)\\v]*\\)";
final String string = " modified: apps/aaaaaa/bbbbbb/ccccff\n"
+ " modified: apps/ami (new commits)\n"
+ " modified: apps/assess (new commits)\n"
+ " modified: apps/ees121 (new commits)\n"
+ " modified: apps/energy_bourse (new commits)\n"
+ " modified: apps/gis (new commits)\n"
+ " modified: apps/hse (new commits)\n"
+ " modified: apps/aa/aaa/a/bb/b/bb/bc/c22/s/df/s/\n"
+ " modified: apps/management (new commits)\n"
+ " modified: apps/payesh (new commits)\n"
+ " modified: external_apps (modified content)\n"
+ " modified: modules/esb_server (new commits)\n"
+ " modified: modules/formbuilder (new commits, modified content)\n"
+ " modified: modules/reporting (new commits)\n"
+ " modified: modules/safir (new commits)\n"
+ " modified: modules/workflow (new commits)\n"
+ " modified: vendor/raya_framework/client (new commits)\n"
+ " modified: vendor/raya_framework/core (new commits)";
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