I'm trying to write a regular expression for matching executable version number.
It can be provided in two ways:
MAJOR.MINOR.TINYMAJOR.MINOR.TINY.BUILD_NUMBER
I do not need to parse these values, just check for match. So, I can:
^\d+[\.\d+]*$. Ok, but this regexp will match strings with 5 and more version parts, i.e 1.2.3.4.5. Also, it will match string like 1..2.3. It would be great to do something like ^[as many digits as you want and only one .]{3,4}$.
P.S. Of course, I can check for something like this ^(\d*)\.(\d*)\.(\d*)$ at first and the for ^(\d*)\.(\d*)\.(\d*)\.(\d*)$ if not matched. But maybe there is a better (smarter) way to do this.
I use re python module for checking the match:
import re
version_regexp = re.compile(r'^\d+[\.\d+]*$')
versions = ['dsvfsdf',
'1.a.3',
'1.2.4',
'1.4..5.6',
'0.3.1',
'a.b.c.d',
'1,2,3']
for i, sample in enumerate(versions):
print('Sample[%d]: %s' % (i, True if version_regexp.match(sample) else False))
Thank you in advance!