With the sections not being of fixed length, the only DIESEL option is to test a range of characters for each section, e.g. for the first section, accounting for 1-3 characters would result in the following DIESEL code:
$(if,$(eq,-,$(substr,$(getvar,dwgname),2,1)),$(substr,$(getvar,dwgname),1,1),$(if,$(eq,-,$(substr,$(getvar,dwgname),3,1)),$(substr,$(getvar,dwgname),1,2),$(if,$(eq,-,$(substr,$(getvar,dwgname),4,1)),$(substr,$(getvar,dwgname),1,3))))