Page 1 of 1

Search text for date?

Posted: Mon Apr 23, 2007 12:42 pm
by tetuanrp
So here's what I got. I'm parsing a data feed, which consists of a block of text. In this text, sometimes there is one date (the text is descriptive text about an online coupon, and the date is the expiration date for the coupon). I want to search through this text, and check to see if there's a date within it, and if so, I want to pull it out into a variable. How can I search the text field and pull out a date?

The dates are coming through in two ways:
m-d-y
and
m/d/y

Any other dates that actually come as text, I'm assuming I won't be able to capture those, but that's only a limited amount anyway (ie. January 25, 2008)

The only idea I had was to maybe break the text up into an array (using a space as the seperator), then running through each array item checking if it's a date? Any ideas?

Thanks in advance!

Posted: Mon Apr 23, 2007 1:02 pm
by Burrito
use a regular expression to search for a date format in your string.

Posted: Mon Apr 23, 2007 2:15 pm
by tetuanrp
Yeah, regular expressions frighten me. I've researched em before, but need to study up on them again. Any good reference?

Posted: Mon Apr 23, 2007 2:18 pm
by Burrito