Phrogz
9/27/2007 5:37:00 PM
On Sep 27, 11:11 am, Phrogz <phr...@mac.com> wrote:
> On Sep 27, 9:55 am, Daniel Waite <rabbitb...@gmail.com> 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", "!"]