Parsing a String in Ruby (Regexp?)
regex, ruby
Solution
string = "Purchases 10384839,Purchases 10293900,Purchases 20101024"
string.scan(/(\w+)\s+(\d+)/).collect { |type, id| { :type => type, :id => id }}
Problem
I've got a string ``` Purchases 10384839,Purchases 10293900,Purchases 20101024 ``` Can anyone help me with parsing this? I tried using StringScanner but I'm sort of unfamiliar with regular expressions (not very much practice). If I could separate it into ``` myarray[0] = {type => "Purchases", id="10384839"} myarray[1] = {type => "Purchases", id="10293900"} myarray[2] = {type => "Purchases", id="20101024"} ``` That'd be awesome!