Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression?

 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I have a question about Regular Expression:
How to perform range searches on Date?
Any help would be appreciated!
Thanks!
[ January 29, 2003: Message edited by: Amy Howard ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it depends on the format of the dates, but in general the answer probably varies from "not easily" to "not without hideously overcomplex patterns you would never want to use in real life". It's probably a mistake to try to do this with just a regex. (This is probably good general advice for rexexes - don't insist on doing everything in one expression.) I'd probably use a simple regex just to locate any data-like pattern, and then parse it with SimpleDateFormat and decide if it's within the desired range. If not, call matcher.find() again to locate the next data. Repeat as necessary.
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim, Thanks for your help! My application is very complicated. It enables the users to search for a specific error with date range from different date format log files. For example, "Error 20089" and from "11/15/2002" to "01/27/2003".
So your suggestion is that to search each date in each date format separately, right?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, maybe. What I meant was to search for any date, and see if it's in the desired range. It sounds like you might be thinking (a) create a list of all eligible dates, then (b) for each date, search for that date in the log file. That sounds pretty inefficient I think. If you've got a 1-year range and a 1-MB log file to search, I wouldn't want to search it 365 times for different strings. But I guess it would be best to continue this here so as not to fragment this discussion unnecessarily.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic