Skip to content

Extract a Numeric Version from Text

Pull the first run of digits and dots out of a string so a human version line becomes a comparable numeric version.

Language: Shell

Added on: 18th August 2026

get_version_string() {
  raw_string="${1:-}"

  # shellcheck disable=SC2001
  version=$(echo "${raw_string}" | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')
  echo "${version}"
}