Groovy web console

subscribe to the feed Subscribe
to this
site
PatternMatch (via #groovywebconsole)
tweet this snippet Tweet
this
script

PatternMatch

Published 1 month ago by Ram with tags Regular Expression
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.util.regex.*

def anAddOnInfo1 = "ARBCI10004"
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+\d[0-4R]$/) {
            addOnVersionFinal = addOnVersion
        } else if (addOnVersion =~ /(^ARBCI)\d+\d[5-99]$/) {
            addOnVersionFinal = "0000"
        } 
    }
    return addOnVersionFinal
}