Need help on splitting the label values based on text.
Label field values are [June_2019_POA1, ABC, July_2020_POA2, XYZ]
So I need to find POA1 and POA2 values exist or not in label.
If the values exist then get them and assign the values to 2 different variables.
FirstPOA1 = JUNE_2019
SecondPOA2 = July_2020
Can anyone help on this plz?
Regex will be your friend for that.
I often use this for reference: https://regex101.com/r/1BscV3/2
Here is how you can use that in groovy:
def labels = ['June_2019_POA1', 'ABC', 'July_2020_POA2', 'XYZ']
def regexPat = /^([a-z|A-Z]*_\d{4})_(\S*)$/
def fieldMap = [POA1:'FirstPOA1', POA2:'SecondPOA2']
def FirstPOA1, SecondPOA2
labels.each{ label->
def matcher = label =~ regexPat
if(matcher.matches()){
if(matcher[0][2] == 'POA1') FirstPOA1 = matcher[0][1]
if(matcher[0][2] == 'POA2') SecondPOA2 = matcher[0][1]
}
}
log.info "FirstPOA1 = $FirstPOA1"
log.info "SecondPOA2 = $SecondPOA2"
Hi @PD Sheehan This script works but need one small changes on it to convert the string to date format. I am looking the output format would be like 06/01/2019 and 07/01/2020.
def fmtfrsPOA1 = FirstPOA1.replaceAll("_",",")
Date dtfirstPOA1 = (Date)fmtfrsPOA1
def dtfirstPOA1format = dtfirstPOA1.format('MM-yyyy')
I tried above but through error. Any help much appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try parsing the poa value as-is by providing the existing format (rather than converting), then format it in the desired format.
new Date().parse( 'MMMM_yyyy',FirstPOA1 as String).format('MM/dd/yyyy')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Its worked. You have solved my issue. Thank you so much
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.