aspose file tools*
The moose likes Java in General and the fly likes Regular Expression? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular Expression?" Watch "Regular Expression?" New topic
Author

Regular Expression?

Amy Howard
Ranch Hand

Joined: Jul 11, 2002
Posts: 86
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

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Amy Howard
Ranch Hand

Joined: Jul 11, 2002
Posts: 86
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

Joined: Jan 30, 2000
Posts: 18671
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regular Expression?