D
Daniel Waite
Hi all, I've an interesting problem. Imagine the following string:
'a1000aa'
I want to break it apart like so:
[ 'a', '1000', 'aa' ]
I did a search on the forums and came up with this regex:
'a1000aa'.scan(/((.)\2*)/).map { |i| i[0] }
Which is pretty close, but it groups on a change of character, so I
would get:
[ 'a', '1', '000', 'aa' ]
I tried playing around with the regex (e.g. swapping the . for (\d|\w))
but to no avail.
Any ideas?
'a1000aa'
I want to break it apart like so:
[ 'a', '1000', 'aa' ]
I did a search on the forums and came up with this regex:
'a1000aa'.scan(/((.)\2*)/).map { |i| i[0] }
Which is pretty close, but it groups on a change of character, so I
would get:
[ 'a', '1', '000', 'aa' ]
I tried playing around with the regex (e.g. swapping the . for (\d|\w))
but to no avail.
Any ideas?