Regex doesn't match in bash

Viewed 26

I have this in my bash file

#!/usr/bin/env bash
LC_ALL=C

local_branch="STORY-409-new-bash-file"

valid_branch_regex="(feature\/|bugfix\/|release\/|hotfix\/)?(PIB\-|STORY\-)(\d+)\-(.+)"
valid_branch_sample="[type]/[ticket-number]-description-with-hyphenated-string, i.e feature/STORY-584-do-something-here"

message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_sample. Your commit will be rejected. You should rename your branch to a valid name and try again."

if [[ ! $local_branch =~ $valid_branch_regex ]]

then
    echo "$message"
    exit 1
fi

exit 0

and it keeps exiting with 1 meaning the regex doesn't match but I'm thinking the regex matches and it should exit with 0. What is wrong with the regex

0 Answers
Related