Split string by Uppercase letters

Hi

I want to split a string by Capital Letters.
I guess that could be done with Pyhton. As I have found the below link. But I can’t seem to get it to work with Python in Revit 2023…?

In example, splitting “TheLongAndWindingRoad” in to “The Long And Winding Road”.
Or event better, into sublist:
0 The
1 Long
2 And

Thanks…

Unfortunately the built in String.Replace node doesn’t work recursively by default, so we can’t make super short work of this…

Fortunately the python is super simple.

import re
txt = IN[0]
OUT = re.findall('[A-Z][^A-Z]*', txt)
3 Likes

(Just for fun) If you wanted to use nodes you could check for matches between the original case and upper case strings. Then add a leading space to break up the words and join back together. You’ll have to remove the leading space but that’s it. Actually pretty simple.

6 Likes

If you have Crumple package installed you can do it this way. I believe the code that @jacob.small provided above is the same code being used by the Crumple node as the output is exactly the same. Although, I do like taking the adventurous path every once in awhile, so I like @Nick_Boyts option also.

2 Likes

Hello

cordially
christian.stan

1 Like