Groovy web console

subscribe to the feed Subscribe
to this
site

Check for zero-padding

Published 2 weeks ago by G. Erickson
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/* New RegEx */
def artifactVersion = '0.2034.111'
def buildNumber = '1'
if (artifactVersion =~ /(^|\.)0[0-9]{1,}($|\.|\-)/) {
    buildNumber = String.valueOf(buildNumber).padLeft(2, '0')
  }
println(buildNumber)

/* Old RegEx */
def artifactVersion1 = '0.2034.111'
def buildNumber2 = '1'
if (artifactVersion1 =~ /0[0-9]{1,}\./) {
    buildNumber2 = String.valueOf(buildNumber2).padLeft(2, '0')
  }
println(buildNumber2)