Semantic Commit Message in PY
Validate Conventional Commits format: type(scope)!: description.
Try it in the PY tester →Pattern
regexPY
^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9\-]+\))?(!)?:\s.+ (flags: i)Python (re) code
pyPython
import re
pattern = re.compile(r"^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9\-]+\))?(!)?:\s.+", re.IGNORECASE)
input_text = "feat(auth): add OAuth2 login"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
The first group captures the commit type from the allowed list. (\([a-z0-9\-]+\))? optionally captures a scope in parentheses. (!)? captures a breaking change marker. :\s requires a colon and space before the description. The i flag makes types case-insensitive.
Examples
Input
feat(auth): add OAuth2 loginMatches
feat(auth): add OAuth2 login
Input
fix!: correct null pointer in parserMatches
fix!: correct null pointer in parser
Input
random commit messageNo match
—