From: Phrogz Date: 2007-09-28T02:40:03+09:00 Subject: Re: Break apart a string by kind of characters On Sep 27, 11:11 am, Phrogz wrote: > On Sep 27, 9:55 am, Daniel Waite wrote: > > > Hi all, I've an interesting problem. Imagine the following string: > > > 'a1000aa' > > > I want to break it apart like so: > > > [ 'a', '1000', 'aa' ] > > irb(main):001:0> s = 'a1000aa' > => "a1000aa" > irb(main):002:0> s.split( /(\d+)/ ) > => ["a", "1000", "aa"] Or, if you want multiple types of character groupings: irb(main):001:0> s = 'hello world, you crazy world!' => "hello world, you crazy world!" irb(main):003:0> s.scan( /[aeiou]+|[b-df-hj-np-tv-z]+|[^a-z]+/ ) => ["h", "e", "ll", "o", " ", "w", "o", "rld", ", ", "y", "ou", " ", "cr", "a", "zy", " ", "w", "o", "rld", "!"]