On ruby’s Regular Extraction of Numbers or Letters with Uncertain Digits in a String

  question, ruby

I have a batch of character strings, and the rule is “number+letter+number+letter+number”. Numbers and letters can be any one or more, such as: 1A03F4F, 16DC203B5R. I want to regularly extract the first number, the first letter, the second number, the second letter and so on. How do you write it?

String#scan

2.5.1 :017 > '16DC203B5R'.scan(/(\d+)*([a-zA-Z]+)*/)
 => [["16", "DC"], ["203", "B"], ["5", "R"], [nil, nil]]
 2.5.1 :010 > '01AB03F4F'.scan(/(\d+)*([a-zA-Z]+)*/)
 => [["01", "AB"], ["03", "F"], ["4", "F"], [nil, nil]]