Groovy web console

subscribe to the feed Subscribe
to this
site

match pattern

Published 5 months ago by Ram with tags regular expression usage
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.util.regex.*

def anAddOnInfo1 = "ARBCI1000100"
def anAddOnInfo2 = "ARBCI10007"
def anAddOnInfoR= "ARBCI0000R"
if (anAddOnInfo1) {
    anSourceDocumentVersion = getAddOnVersion(anAddOnInfo1)
} else if (anAddOnInfo2) {
    anSourceDocumentVersion = getAddOnVersion(anAddOnInfo2)
} else if (anAddOnInfoR) {
    anSourceDocumentVersion = getAddOnVersion(anAddOnInfoR)
}


def getAddOnVersion(def addOnVersion) {
    def addOnVersionFinal = null
    if (addOnVersion) {
        if (addOnVersion =~ /(^ARBCI)\d{3}\d[0-4R]$/) {
            addOnVersionFinal = addOnVersion
        } else if (addOnVersion =~ /(^ARBCI)\d+\d[1-9][0-9]$/) {
            addOnVersionFinal = "0000"
        } 
    }
    return addOnVersionFinal
}