That's written in Python. It sounds like there's some variability in the value, which will make your logic a bit complex. It's too bad the SURVEYNUMBER values aren't spread across three separate fields, which would make it easy to concatenate into one label expression. Anyway, here's something that has worked for a few of the examples you provided:
def label(string):
firstLine = string.split("-")[0]
intVals = []
for x in range(2,len(string)):
if string[x] in ["0","1","2","3","4","5","6","7","8","9"]:
intVals.append(x)
start = min(intVals)
end = max(intVals) + 1
secondLine = string[start:end]
if len(string.split("-")) > 2:
thirdLine = string.split("-")[2]
elif len(string.split("-")) == 2:
thirdLine = string.split(secondLine)[1]
else:
thirdLine = ""
returnLabel = "{0}\n{1}\n{2}".format(firstLine,secondLine,thirdLine).rstrip("\n")
print(returnLabel)
return returnLabel
I tried the following labels:
myString1 = "G-1320Ab"
myString2 = "G-1320"
myString3 = "G-132"
myString4 = "A-3035-I"
myString5 = "A-3035-II"
All came back as I think you'd like.
The function is the equivalent of the FindLabel function in the examples. You won't need the print statement on line 17, I was just doing that to verify what was returned.