Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression for date search 1

Status
Not open for further replies.

AMayer

Programmer
Sep 23, 2000
82
US
I've only ever accomplished the most basic of regular expressions so this problem has been cooking my brain all morning.

I'm trying to use a regular expression to search for dates in the format: Jun 12 thu. I'm searching these out in a large text file. Simple date formats like 6/12/03 would be no problem but I've never dealt with multiple text options like jan|feb|mar... before and can't seem to get it.

Can anyone show me what the reg expression should look like?
 
You'll prolly need to be more specific on your limitations to find exactly what you want... but here's something that works for what you've stated. Just expand the month and day lists as you need.

Code:
  $pattern="/(jun|jan|feb) ([0-9]+) (mon|tue|thu)/";
  preg_match($pattern, $product, $matches);

  $matches[1] will contain your month
  $matches[2] will contain your day in numeric format
  $matches[3] will contain the day
  $matches[0] will contain the entire string.

g'luck, feel free to ask for explanation or clarification if it's unclear what's going on.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top