Stefano Crocco
6/1/2008 3:21:00 PM
On Sunday 01 June 2008, Dan __ wrote:
> Alright, this is probably a really simple question to answer, but I just
> can't think of how to do it at the moment. Say I had a string, similar
> to the following:
>
> 12343:3,73820:1,183874:8
>
> What I would like to be able to do is remove all colons, and everything
> between the colons and the commas, and then split the string at the
> commas (and then split the original string again at the commas, and then
> deal with the numbers after the colons, but thats the easy part, since
> I'll already know which index of the array to look at).
>
> I know its kind of an odd thing to want to do, but it helps keep things
> organized and in one place. Any ideas on how to do this?
I'm not sure I understand you correctly or not. At any rate, this code will
transform your example string to "12343,73820,183874", then split it in
["12343","73820","183874"]:
str.gsub(/:[^,]*(?:$|(?=,))/,'').split( ',')
I hope this helps
Stefano