I've got the following code and have looked at numerous examples but cannot figure out what I'm doing wrong. I know the regular expression works (see https://regex101.com/r/cB9hN1/1) - just not in my bash script. It's for a git update hook, but clearly I'm doing something wrong! Here's what I've got:
regex='ref:( |)([D]|[U])([E]|[S])(\d+)';
string="My commit ref: US2233556"
if [[ $string =~ $regex ]];
then
echo "[SUCCESS] Your message contains ref: for a Story or Defect."
exit 0
else
echo "[POLICY] Your message is not formatted correctly. Please include a \"ref: USXXXXX\" or \"ref: DEXXX\" in the commit message."
exit 1
fi
I'd appreciate any help! Thank you!
regex='ref:( |)([DU])([ES])([0-9]+)';.