为什么下面的正则表达式工作:https://regex101.com/r/nI8xB8/1但在bash脚本中不起作用
^(feature|bugfix|refactor|release|hotfix|other)\/[a-z0-9._-]+\/[a-z0-9._-]+$
带测试字符串
feature/XXXX-23/xxxx-xxxx
但是feature/no-ref/xx-xxxx
可以用
脚本
local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(feature|bugfix|refactor|release|hotfix|other)\/[a-z0-9._-]+\/[a-z0-9._-]+$"
message="\x1B[01;91m Some message. \x1B[0m"
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo "$message"
exit 1
else
echo "\x1B[01;92m Your branch name is okay \x1B[0m"
fi
1条答案
按热度按时间zengzsys1#
我让它与下面的正则表达式一起工作
使用POSIX类:
:alnum:
和排序规则也允许_
和-
参考:
https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions