-1

I am looking for the right regex to validate the kubernetes version before i create the cluster. here are few examples kubernetes version. Can somebody please help on finding the right regex.

    1.18.6-gke.4801",
    1.17.9-gke.1504
    1.17.9-gke.6300
Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397
akhinair
  • 13
  • 5

1 Answers1

-1

You might want to try something like this:

if [[ $GKE_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]-gke\.[0-9]+$ ]]; then
    echo "OK: Good GKE Version: ${BASH_REMATCH[0]}"
else
    echo "Bad GKE Version"
fi

Or something like this may be:

[[ "1.17.9-gke.1504" =~ ^[0-9]{,2}\.[0-9]{,2}\.[0-9]{,2}-gke\.[0-9]{4}$ ]] && echo "Good GKE Version" || echo "Bad GKE Version" 
1218985
  • 6,361
  • 2
  • 19
  • 26