import re
regex = re.compile(r"^(?::\w*:|(?:\ud83c[\udf00-\udfff])|(?:\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55])\s(?<type>[a-zA-Z-,\/]+)(?:\((?<scope>.*)\))?!?:\s(?<subject>(?:(?!#).)*(?:(?!\s).))(?:\s\(?(?<ticket>#\d*)\)?)?$", flags=re.MULTILINE)
test_str = ("// 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")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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 Python, please visit: https://docs.python.org/3/library/re.html