how to extract minor version from major version variable

Hello Team,

What is the correct way to extract just major version from full version like ,

full version is : 2.8.3
need version: 2.8

do we use split or regex

i tried with regex_replace(‘^([0-9])\.([0-9]).’, ‘\1.\2’)

but is there any other better way to do it

If you can manage to express your problem in terms of a test, then you can use Ansible’s version test: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/version_test.html

Otherwise, Ansible’s own utils/version.py (which is used by the version test) uses the following regex. Maybe that will inspire you.

Regular expression taken from

https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string

SEMVER_RE = re.compile(
r’‘’
^
(?P0|[1-9]\d*)
.
(?P0|[1-9]\d*)
.
(?P0|[1-9]\d*)
(?: