Regex matching in a Bash if statement

后端 未结 3 989
逝去的感伤
逝去的感伤 2020-11-28 01:42

What did I do wrong here?

Trying to match any string that contains spaces, lowercase, uppercase, or numbers. Special characters would be nice too, but I think that r

3条回答
  •  执笔经年
    2020-11-28 02:32

    In case someone wanted an example using variables...

    #!/bin/bash
    
    # Only continue for 'develop' or 'release/*' branches
    BRANCH_REGEX="^(develop$|release//*)"
    
    if [[ $BRANCH =~ $BRANCH_REGEX ]];
    then
        echo "BRANCH '$BRANCH' matches BRANCH_REGEX '$BRANCH_REGEX'"
    else
        echo "BRANCH '$BRANCH' DOES NOT MATCH BRANCH_REGEX '$BRANCH_REGEX'"
    fi
    

提交回复
热议问题