Could you please help in giving me the regex for the following version number format:
e.g. 10.01.03-13
< major >.< minor >.< patch >-< buildnumb >
You can use a simple match on digits following the pattern of digit-dot-digit-dot-digit-hyphen-digit, since groovy uses the java engine.
(\d+)\.(\d+)\.(\d+)\-(\d+)
#1
= major
#2
= minor
#3
= patch
#4
= buildnumb
You can also use named groups if you fancy:
def version = '10.01.03-13'
def parser = /(?<major>\d+).(?<minor>\d+).(?<revision>\d+)-(?<build>\d+)/
def match = version =~ parser
if(match.matches()) {
def (major, minor, revision, build) = ['major', 'minor', 'revision', 'build'].collect { match.group(it) }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With