Split, strip and join again


Oh how I wish I could use wildcards … but perhaps you guys can help me out.

I have a list of revit elements, some loadable families start with our firm’s code: and now I’d like to strip that code since it’s of no use (therefor clutters) to others.

[number][number][FIRMCODE 3 CHAR][FAMILYABBR, 1/2/3 CHAR] - [explanation]

So raw input:
10_VDP_GM - test
16_VDP_C - weeeee
54_VDP_DET - bleegghhh

Should become:

I’d like to have the ‘explanation’ part. So first thoughts: String.split " - " … right? My thoughts to – initially. BUT string.split does break EVERY instance of that separater.

So somehow I have to count the sublist items
IF > 1: remove first sublist item and join the others
IF == 1: do nothing

OR is there a better way?
Basicly [VDP - ] would be sufficient -.-

Find the index of “-”, get the total length of the string, return all characters after index+1. Also, you could use excel to do this then retrieve the processed data in Dynamo; way more efficient.

Pfff, though cookie.

So an attempt:

  • get index of ‘separator’: " - "
  • get length of string
  • get length of ‘separator’ (codeblock ‘3’)
  • math, and make negative to use
  • list.takeitems (from back of list)

But obviuously it should be string not list … perhaps it’s too late. I can’t see it.

Like this:



Thnx! Added a conditional check in case the separator isn’t used in a string. it works!

You can use regex with the following pattern \S*\s-\s like shown in this post:


You can also use a line of code in python:

OUT=[i.split('- ')[1] if '- ' in i else i for i in IN[0]]

or without list comprehension:

for i in IN[0]:
	if '- ' in i:
		OUT.append(i.split('- ')[1])

1 Like


I really should learn how to “python”. Good thing I know php so I can understand your short version too. thanks.