import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[A-Z-0-9]+ .*(?<type>chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\\\_\\(ツ\\)_\\/¯)(?<scope>\\(\\w+\\)?((?=:\\s)|(?=!:\\s)))?(?<breaking>!)?(?<subject>:\\s.*)?|^(?<merge>Merge.* \\w+)|^(?<revert>Revert.* \\w+)";
final String string = "### Should Pass Test\n\n"
+ "NV-1234 chore: change build progress\n"
+ "DT-123456 docs: update xdemo usage\n"
+ "QA-123 ci: update jenkins automatic backup\n"
+ "CC-1234 feat: new fucntional about sync\n"
+ "Merge branch master into develop\n"
+ "Reverted: Revert \"support UV113 feature & bugfix branches make full build\n"
+ "Merge pull request #36 in cicd from test to developSquashed commit of the following: com\n\n"
+ "### Failed to match test\n"
+ "NV-1234 build: update \n"
+ "NV-1234 Chore: change progress\n"
+ "DT-123456 Docs: update xdemo\n"
+ "QA-123ci: update jenkins automatic backup\n"
+ "CC-1234 Feat: new fucntional about sync\n"
+ "DT-17734: 8.2.2 merge from CF1/2- Enhance PORT.STATUS to identify Python processes initiated\n"
+ "DT-17636 fix AIX cord dump issue\n"
+ "DT-18183 Fix the UDTHOME problem for secure telnet\n"
+ "DT-18183 Add new condition to get UDTHOME\n"
+ "DT-15567 code merge by Peter Shen.";
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