jbullock35 has asked for the wisdom of the Perl Monks concerning the following question:
I occasionally have strings like this: A # B # 1 # 2The 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 # 2This 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. |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: rearranging matched parts of a string while using /g and without using split
by ikegami (Patriarch) on Jun 22, 2010 at 18:23 UTC | |
Re: rearranging matched parts of a string while using /g and without using split
by Yary (Pilgrim) on Jun 22, 2010 at 17:45 UTC | |
Re: rearranging matched parts of a string while using /g and without using split
by kennethk (Abbot) on Jun 22, 2010 at 18:51 UTC |