I have the following regex pattern I'd like to use to validate git commit messages. (((CMS-)|(UIDEV-)|(CONTENT-)|(RPT-))[0-9]+\\s-\\s)|(NOTICKET- )
However when I have a sample message of CMS-7120 - test commit message
, the regex match fails and enter the if
condition. I used to have \\d+
but realized that wasn't POSIX compliant and changed it above but unsure why I'm not getting a match. Tested it on regex101 and I do get a match there. Any thoughts on what is wrong here?
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
pattern="(((CMS-)|(UIDEV-)|(CONTENT-)|(RPT-))[0-9]+\\s-\\s)|(NOTICKET- )"
message="$(cat $1)"
if [[ !($message =~ $pattern) ]]; then
echo "bad commit message"
exit 1
fi