Group text elements within a string

Hello everyone,

I have strings in the form of


These basically are chemical side chains of a molecule listed in form of a string. You have your chemical group (F, Me), followed by the number of occurence (2) and the position within the molecule (1,2,…,6).

I’d like to transform this into a string like this: F4(1,1’,6,6’)-Me2(3,4).

Is there a a way to do that? Or is there alternatively a good way to treat the numbers within a string as counters and list elements?

Many thanks for your help!

Hi @kermitthefrog01

based on your example i assume the delimiter between the chemical groups is always the same.
This solution is probably not the smartest way, but it should work.

Example.knwf (56.1 KB)


1 Like

Hi @morpheus,

thanks so much, that’s a really neat solution!

I had to adjust my workflow a bit to allow for cases like Me(3) where I’d get missing values but other than that this is perfect. Plus, I learned a lot about unpivoting, splitting and grouping - that would have taken me days to figure out on my own.

Cheers! :smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.