It's not easy, the functions in VBScript are limited. I think you would be better standardizing to python as it offers far more functions and options than VBScript which is on the way out. However, in the interest of just answering the question...
As I understand it you want to take the first word if there is a dash but only display the alphanumeric characters and if there is no dash then just the contents of BA2.
Function FindLabel ([BA2])
if InStr([BA2],"-") > 0 then
BA_Split = split([BA2],"-")
ThisWord = BA_Split(0)
OutString = ""
for index = 1 to len(ThisWord)
SingleLetter = mid(ThisWord,index,1)
if asc(SingleLetter) >= 48 and asc(SingleLetter) <= 57 then
OutString = OutString & SingleLetter
elseif asc(SingleLetter) >= 65 and asc(SingleLetter) <= 90 then
OutString = OutString & SingleLetter
elseif asc(SingleLetter) >= 97 and asc(SingleLetter) <= 122 then
OutString = OutString & SingleLetter
end if
next
FindLabel = OutString
else
FindLabel = [BA2]
end if
End Function
There is no isalnum()
in VBScript, so instead I use the ASCII ranges for 0 to 9, A to Z and a to z... if in this range then append to OutString
The second function is the same as the first except you use the second word:
Function FindLabel ([BA2])
if InStr([BA2],"-") > 0 then
BA_Split = split([BA2],"-")
ThisWord = BA_Split(1)
OutString = ""
for index = 1 to len(ThisWord)
SingleLetter = mid(ThisWord,index,1)
if asc(SingleLetter) >= 48 and asc(SingleLetter) <= 57 then
OutString = OutString & SingleLetter
elseif asc(SingleLetter) >= 65 and asc(SingleLetter) <= 90 then
OutString = OutString & SingleLetter
elseif asc(SingleLetter) >= 97 and asc(SingleLetter) <= 122 then
OutString = OutString & SingleLetter
end if
next
FindLabel = OutString
else
FindLabel = [BA2]
end if
End Function