I occasionally have strings like this:
A # B # 1 # 2
The strings have two types of data that I care about. (In this case, letters and numbers.) Each type has the same number of instances within a string. (In this case, there are two letters and two numbers. But sometimes I will have ten of each type.) And all instances of the second type follow all instances of the first type. (In this case, the all of the letters are listed before the numbers begin.)
I want to rearrange the string so that I end up with
A # 1 # B # 2
This is easy to do with split, but is there a way to do it in a single line (presumably without using split)?
Crucially, the number of groups that I want to rearrange will vary. In the example that I've given, there are just four groups, but in other cases there will be eight or ten or more. I'd like a single regular expression that can handle strings that differ on this dimension.