import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?::\\w*:|(?:\\ud83c[\\udf00-\\udfff])|(?:\\ud83d[\\udc00-\\ude4f\\ude80-\\udeff])|[\\u2600-\\u2B55])\\s(?<type>[a-zA-Z-,\\/]+)(?:\\((?<scope>.*)\\))?!?:\\s(?<subject>(?:(?!#).)*(?:(?!\\s).))(?:\\s\\(?(?<ticket>#\\d*)\\)?)?$";
final String string = "// Not Matched\n"
+ "chore(scope): test\n\n"
+ "hello :test: test\n\n"
+ ":start:test: test\n\n"
+ "// Matched\n\n"
+ ":hello: test: test\n\n"
+ ":start: chore(scope): test\n\n"
+ ":start: chore(scope): test #123\n\n"
+ ":memo: docs: update README.md\n\n"
+ ":start: chore(scope): i have a word #123\n\n\n"
+ ":package: feat(parser-opts): extract parser-opts packages\n\n\n"
+ ":sparkles: feat(changelog): 添加中文标题\n\n"
+ ":sparkles: feat(changelog): add chinese title\n\n"
+ "✨ feat(unicode): add unicode support\n\n"
+ "😌 test(only): add unicode support\n\n"
+ ":sparkles: feat: hello world (#100)\n\n"
+ ":green_heart: fix-ci(ci/cd): added release rules for all cz-emojis\n\n"
+ ":green_heart: ci/cd(config): changed config for cz-emojis\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