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'''
^
(?P<major>0|[1-9]\d*)
\.
(?P<minor>0|[1-9]\d*)
\.
(?P<patch>0|[1-9]\d*)
(?:
-
(?P<prerelease>
(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)
(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*
)
)?
(?:
\+
(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)
)?
$
''',
flags=re.X
)
On 10/25/23 8:51 AM, Sameer Modak wrote:
i tried with regex_replace('^([0-9])\\.([0-9]*).*', '\\1.\\2')
but is there any other better way to do it
On Wednesday, October 25, 2023 at 6:16:34 PM UTC+5:30 Sameer Modak wrote:
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
--
You received this message because you are subscribed to the Google
Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7f71e811-5c05-483b-be5b-f50261860d82n%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/7f71e811-5c05-483b-be5b-f50261860d82n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Todd
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/e4bfd594-e772-40a2-bbec-9cf9f6115a67%40gmail.com.