• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Using Patterns for Date String  RSS feed

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

i need some suggestions in woking with pattern/matcher classes for dates.What i am doing is giving an input date as "24 Feb 2002".My output should be displayed as :-
//d+//s//w+//d{4},//d+//s//w+//d+ etc (that is all possible combination which if i give as the argument to Pattern.matcher() and using the matcher class,output is the date "24 Feb 2002" )ie i am doing a reverse process.

i was putting the above string in a character array and my idea was to assign d ,w one by one for digits and words respectively and then display the final output as //d+//s//w+//d{4} or whatever.Any better idea?

Thanks in advance
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you're trying to do... Do you actually want to parse some string containing dates in a specific format and find them in this string? Or format dates from one formatting into another? If first is true, then the regex to use would be more like: "\\d+\\s\\w+\\s\\d{4}" (notice using backslashes instead of slashes). But you must be aware, that such regex may also match expressions like e.g. '12323434 _123_ 1342', which is not really a date...
If you're actually trying to reformat a date stored as string, take a look at java.text.DateFormat / java.text.SimpleDateFormat API.

Ok now I think I know what you're trying to do. Do you actually want to put in some expression and receive as output regexes that would match it? There is Pattern#quote method, but as far as I know, it only returns literal pattern (no character classes)... Retrieving pattern that uses character classes from a given input sequence doesn't seem like a trivial task.
[ July 30, 2008: Message edited by: Dariusz Kordonski ]
 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i am giving the input as "24 Feb 2002" in a string.what my code should do is to produce the possible regular expression for that string like //d+//s//w+//d{4},//d+//s//w+//d+ etc for this case.Hope its clear now.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!