❝昨天推送的文章介绍到1000 个安装包整理,使用了python脚本实现版本号的匹配。❞
Qt的安装包&源码中有好几种版本号需要匹配。比如:
代码语言:javascript复制1.41
2.00
2.2.2-4bpp_grey
2.3.2
3.3.8b
python代码:
代码语言:javascript复制all_package_list = [
'qt-1.41.tar.gz',
'qt-2.00.tar.gz',
'qt-embedded-2.2.2-4bpp_grey.diff.gz',
'qt-x11-2.3.2.tar.gz',
'qt-x11-free-3.3.8b.tar.gz',
]
for package in all_package_list:
match_object = re.search(r'(d{1,2}).(d{1,2})(?:.(d )[0-9a-zA-Z_-]*){0,1}', package)
if match_object:
marjor = 0
minor = 0
patch = 0
if match_object.group(1):
marjor = int(match_object.group(1))
if match_object.group(2):
minor = int(match_object.group(2))
if match_object.group(3):
patch = int(match_object.group(3))
print(marjor, minor, patch)
打印输出:
代码语言:javascript复制1 41 0
2 0 0
2 2 2
2 3 2
3 3 8
相关:
匹配版本号
版本号定义知多点