Semantic Commit Message in GO
Validate Conventional Commits format: type(scope)!: description.
Try it in the GO tester →Pattern
regexGO
^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9\-]+\))?(!)?:\s.+ (flags: i)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?i)^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9\-]+\))?(!)?:\s.+`)
input := `feat(auth): add OAuth2 login`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
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
—