How to - Split a string containing letters and numbers

Hello All,

I have search long as hard and haven’t been able to find a smart / short solution to the following issue.

All i’m trying to do is split strings when it changes from letters to numbers.

ie. from the above i’d want to obtain a list formatted as;

List
0

[0] CB
[1] 100

1

[0] CL
[1] 105

PLEASE NOTE: This is NOT as simple as removing a certain number of numbers / characters from each end as there will not always be 2 letters at the start and 3 numbers at the end, it changes. It will always be letters followed by numbers though, so i could have ABCDEFG200.

Any help with this would be much appreciated.

I ended up with a massive dynamo workflow that still didn’t work and i feel like can probably be done really easily if you know how!

Thanks,
Jack.

There should be some simple solution to this but, the solution that comes to my mind is to

  1. Create a list with strings(0-9)
    2.create a for or while loop to see if the element is in list
    3.if yes get the index of that letter and split at index.

Hi Saju,

Unfortunately i’m not familiar with loops.

I had tried something quite similar with a list of strings (0-9). Looking to see if any of those numbers were in the string and then counting the “true” results but this doesn’t work when you have multiple occurrences of the same number and i couldn’t figure out how to get the occurrences to work for my scenario. This solution was a very long winded solution anyway so i gave up lol

Essentially i just need to split the string 1 character before the value is a number.

Think i’ve crack it with ‘FindRegularExpression’ node. Seems to be working perfectly!

1 Like

Here’s an ootb option that checks for upper/lowercase matches (numbers).

4 Likes

Nice technique! Took me a little while to understand what it was doing (thanks for showing the watch nodes lol very helpful).


Another version OOTB.
How did you combine the 2 lists to get what you mentioned ?

List
0

[0] CB
[1] 100

1

[0] CL
[1] 105

I didn’t need to get the list in that format in the end. I just needed the text / numbers split up so i could alter the string and input other bits;

1 Like

Just for clarity, the String.Replace - replaceWith input is just a blank string;

image