After working with a Regex supplied by Cary (thank you!), I realized it is dropping the last date in the string when I run it in IRB. Here is the code and the output. Can anyone tell me why this is happening and how to fix it?
require 'rubygems'
require 'nokogiri'
require 'open-uri'
str = "September 19, 20, 25, 26, October 2, 3, 4, 10, November 3, 12, 17"
dates=str.scan(/\D+(?:\d+,\s+)+/).map { |s| [ s[/[a-z]+/i], s.scan(/\d+/) ] }
p dates
The output is the following. As you can see, November only returns 2 dates but there are 3 in the string. It drops November 17.
[["September", ["19", "20", "25", "26"]], ["October", ["2", "3", "4", "10"]], ["November", ["3", "12"]]]
C:\RailsInstaller\Ruby1.9.3\nokogiri> –