Semantic Commit Message
Validate Conventional Commits format: type(scope)!: description.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\\([a-z0-9\\-]+\\))?(!)?:\\s.+", "i");
const input = "feat(auth): add OAuth2 login";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
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+.
Go (RE2) code
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.
Pattern
^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9\-]+\))?(!)?:\s.+ (flags: i)Raw source: ^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9\-]+\))?(!)?:\s.+
How it works
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
—Common use cases
- •Git commit-msg hooks
- •Automated changelog generation
- •PR title validation in CI
- •Release tooling (semantic-release, changesets)
Related patterns
Terraform Resource Block Header
Text ProcessingMatch the opening line of a Terraform `resource "type" "name" {` block, capturing the resource type and local name.
Base64 String
Text ProcessingMatch Base64-encoded strings, including proper padding with = and == characters.
C-Style Block Comment
Text ProcessingMatch C-style /* ... */ block comments across multiple lines.
Duplicate Word
Text ProcessingDetects consecutive duplicate words using a backreference.