import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^:(\\w+):\\s+((?:\\s*(?!:)[^\\s]+)+)";
final String string = ":6585d0f0ba88767ac3b590f719596d864d73e9c1:\n\n"
+ "harmonicbalance/src/harmonicbalance/HarmonicBalanceFlowModel.cpp\n"
+ "harmonicbalance/src/harmonicbalance/HbFlutterModel.cpp\n\n\n\n"
+ ":8302994b565553c83a048b8905ae597349d99627:\n\n"
+ "emp/src/emp/PhasePairSingleParticleReynoldsNumber.h\n"
+ "emp/src/emp/TomiyamaDragCoefficientMethod.cpp\n\n\n"
+ ":9da194f17ec08bb20ad1be8df68b78ca137ab18a:\n\n"
+ "combustion/src/combustion/ReactingSpeciesTransportBasedModel.cpp\n"
+ "combustion/src/complexchemistry/TurbulentFlameClosure.cpp\n"
+ ":6a59f0be1e347a65e525e58742bb304639ea9bc4:\n\n"
+ "meshing/src/meshing/SurfaceMeshManipulation.cpp\n"
+ "physics/src/discretization/FvIndirectRegionInterfaceManager.cpp\n"
+ "physics/src/discretization/FvIndirectRegionInterfaceManager.h\n"
+ "physics/src/discretization/FvRepresentation.cpp\n"
+ "physics/src/discretization/FvRepresentation.h\n"
+ ":64b7f6d36b11b6cd94c20cad53463b7deef8c85a:\n\n"
+ "resourceclient/src/resourceclient/ResourcePool.cpp\n"
+ "resourceclient/src/resourceclient/ResourcePool.h\n"
+ "resourceclient/src/resourceclient/RestClient.cpp\n"
+ "resourceclient/src/resourceclient/RestClient.h\n"
+ "resourceclient/src/resourceclient/test/ResourcePoolTest.cpp";
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