I am trying to parse a string in the specific format using this code:
pattern = "XX-XX-XXXX"
item = "abcdefghk"
lenplus = pattern.index("-")
fitem = item[0:lenplus]
result = pattern.split("-")
for a in result:
length = len(a)
lengthplus = lenplus + length
sitem = item[lenplus:lengthplus]
lenplus = length + lenplus
fitem = fitem + "-" + sitem
print(fitem)
I am getting below result
ab-cd
ab-cd-ef
ab-cd-ef-ghk
but I want
ab-cd-efgh
How can I achieve this XX-XX-XXXX format?
print(f"{item[:2]}-{item[2:4]}-{item[4:8]}")