I have a string ruby something like this.
mystring = "some string value with a date 02/02/2002"
and I would like to extract just the date in order to store it in a database. I am pretty sure I’m going to need some sort of regex and way of searching for the pattern and grabbing it from the string.
Not real sure what needs to be done here.
I found this Regex online that is supposed to allow you to match that date formate.
reg = Regexp.new("^\d{1,2}\/\d{1,2}\/\d{4}$")
How would I go about using that to parse out the above date from the string ?
How about this?
Note that you don’t need the
^and$in your regex as you won’t be matching the string in its entirety.