I have a folder with a bunch of packages, each with their version in their name. Im trying to use regex to create a list with those versions to be used later.
Some examples:
Input:
libpci-dev_3.5.2-1_amd64.deb
libpcre3-dev_8.39-12_amd64.deb
libaprutil1-ldap_1.6.1-4_amd64.deb
nftables_0.9.6-1~bpo10+1_amd64.deb
libkdb5-9_1.17-3+deb10u3_amd64.deb
libc-dev-bin_2.28-10+deb10u1_amd64.deb
libboost-locale1.67.0_1.67.0-13+deb10u1_amd64.deb
I want to delete the front of the package name as well all the amd64 and .deb as well as the _ or - surrounding the versions and then just leave the version of the package in the list
Expected output:
3.5.2-1
8.39-12
1.6.1-4
0.9.6-1~bpo10+1
9_1.17-3+deb10u3
2.28-10+deb10u1
1.67.0_1.67.0-13+deb10u1
I managed to select only the numbers, but im having issues with the last examples, where there is also letters involved
>Solution :
Versions are started after _, so 9_1.17-3+deb10u3 should be 1.17-3+deb10u3, and you can extract those using the following regex.
_(.*)_amd64\.deb
Python Example
import re
packages = """libpci-dev_3.5.2-1_amd64.deb
libpcre3-dev_8.39-12_amd64.deb
libaprutil1-ldap_1.6.1-4_amd64.deb
nftables_0.9.6-1~bpo10+1_amd64.deb
libkdb5-9_1.17-3+deb10u3_amd64.deb
libc-dev-bin_2.28-10+deb10u1_amd64.deb
libboost-locale1.67.0_1.67.0-13+deb10u1_amd64.deb"""
versions = re.findall(r"_(.*)_amd64\.deb", packages)
print(*versions, sep="\n")
OUTPUT
3.5.2-1
8.39-12
1.6.1-4
0.9.6-1~bpo10+1
1.17-3+deb10u3
2.28-10+deb10u1
1.67.0-13+deb10u1