import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(build|ci|docs|feat|fix|perf|refactor|style|test)(|!): [a-z].+?((, fixes #\\d+)*)($|\\n|\\r|\\n\\r)";
final String string = "Remove 'ddev pause' and its tests\n\n"
+ "Add healthcheck to router so we wait for it to be started\n\n"
+ "Add new Amplitude Property DDEV-Environment\n\n"
+ "test: optimize caching of downloaded assets\n\n"
+ "docs: auto create commands documentation\n\n"
+ "docs: re-introduce Rancher Desktop docs\n\n"
+ "fix: avoid type: php to detected project type but instead show a warning, fixes #4403, fixes #1234\n"
+ "build: bump docker-compose to 2.19.0\n\n"
+ "feat: allow multiple upload dirs, fixes #4190, fixes #4796\n\n"
+ "feat!: add ddev dbeaver command, fixes #4947\n\n"
+ "docs: add more extensive custom command examples, fixes #4926\n\n"
+ "refactor: enabled Mutagen by default on Mac and Windows, fixes #4637\n\n"
+ "refactor: avoid calling stop hooks if app is already stopped\n";
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