Doesn't necessarily solve the desire to capture )!:
as breaking group but this does seem to follow conventional commits specs 1-5 + 13.
^(?<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\_\(ツ\)_\/¯)(?<scope>\(\w+\)?((?=:\s)|(?=!:\s)))?(?<breaking>!)?(?<subject>:\s.*)?|^(?<merge>Merge \w+)
https://regex101.com/r/XYC04q/11
Gitlab Push Commit Regex
However, if you are using a platform like GitLab and want to set push rule to commit messages as of v13(?) they are using re2 standards and Golang parser.
Here it is for that Gitlab.
Note that GitLab enables the global flag (?m) which gave me some difficulty. Discussion on gitlab
| Restrict by commit message | Starter 7.10 | Only commit messages that match this regular expression are allowed to be pushed. Leave empty to allow any commit message. Uses multiline mode, which can be disabled using (?-m)
. |
source doc
## simplified and modified for gitlab's
^((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\_\(ツ\)_/¯)(\(\w+\))?(!)?(: (.*\s*)*))|(Merge (.*\s*)*)|(Initial commit$)
## RE2 compliment but doesn't work on GitLab at this time
^(?P<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\_\(ツ\)_/¯)(?P<scope>\(\w+\))?(?P<breaking>!)?(?P<subject>:\s.*)?|^(?P<merge>Merge \w+)
https://regex101.com/r/XYC04q/28
GitLab using Terraform Push Rule Regex
Note if you are trying to use Terraform for Gitlab with Regex, note that Terraform parses the string prior to Gitlab requiring some bonus escapes.
resource "gitlab_project_push_rules" "github_flow" {
project = gitlab_project.project.id
# Conventional Commits https://www.conventionalcommits.org/en/v1.0.0/
commit_message_regex = "^((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\\\_\\(ツ\\)_/¯)(\\(\\w+\\))?(!)?(: (.*\\s*)*))|(Merge (.*\\s*)*)|(Initial commit$)"
branch_name_regex = "(^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\\\_\\(ツ\\)_\\/¯)\\/[a-z0-9\\-]{1,55}$)|master"
prevent_secrets = true
}