# how to extract minor version from major version variable

**URL:** <https://forum.ansible.com/t/how-to-extract-minor-version-from-major-version-variable/38547>\
**Category:** Ansible Project\
**Created:** [October 25, 2023, 12:46pm UTC](https://forum.ansible.com/t/how-to-extract-minor-version-from-major-version-variable/38547 "2023-10-25T12:46:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [October 25, 2023, 12:46pm UTC](https://forum.ansible.com/t/how-to-extract-minor-version-from-major-version-variable/38547/1 "2023-10-25T12:46:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [October 25, 2023, 12:51pm UTC](https://forum.ansible.com/t/how-to-extract-minor-version-from-major-version-variable/38547/2 "2023-10-25T12:51:09Z")

</div>

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

but is there any other better way to do it

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 25, 2023, 3:14pm UTC](https://forum.ansible.com/t/how-to-extract-minor-version-from-major-version-variable/38547/3 "2023-10-25T15:14:24Z")

</div>

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](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](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\*)  
(?:
