Reputation: 11
I'm doing a CI/CD script for my project, and I'm trying to check if the git tag matches a SemVer regex expression, but this always returns "Not Match".
I try this expression on regex101 site and give "1.0.3" as a test string, it works fine.
#!/bin/bash
SEMVER_FORMAT="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
GIT_TAG="1.0.3"
# Debug: Check the value of GIT_TAG
echo "GIT_TAG: '$GIT_TAG'"
# Test Regex matching
if [[ "$GIT_TAG" =~ $SEMVER_FORMAT ]]; then
echo "Match"
else
echo "No Match"
fi
What is wrong with this?
Upvotes: 0
Views: 42