I have written a small Python function to extract version info from a string. Input is of format:
- v{Major}.{Minor}[b{beta-num}]
Eg: v1.1, v1.10b100, v1.100b01
Goal is to extract Major, Minor and beta numbers.
import re
def VersionInfo(x):
reg = re.compile('^v([0-9]+)([.])([0-9]+)(b)?([0-9]+)?$')
return reg.findall(x)
if __name__ == '__main__':
print(VersionInfo('v1.01b10'))
print(VersionInfo('v1.01'))
print(VersionInfo('v1.0'))
Output:
[('1', '.', '01', 'b', '10')]
[('1', '.', '01', '', '')]
[('1', '.', '0', '', '')]
Question is:
- Is it sufficient to cover all cases?
- Better regex?
v1.1b
valid? (i.e. beta with no beta number) \$\endgroup\$b
and.
as well? \$\endgroup\$