This has probably been answered dozens of times, couldn't find the answer though...
Anyway, working in a Smalltalk environment I have a string composed of three parts like this: "ttm 4/6/97 00:08"
. The string is very variable, meaning some part may be missing (so it would be a string composed of less then three parts like "ttm 4/6/97"
) and the order might be different ("00:08 ttm 4/6/97"
). Also, the date might be missing digits ("04/6/1997"
, "4/06/97"
, etc.). Luckily, the spaces as separators are constant plus, there are no leading or trailing spaces.
What I need is to find the date in the string and match two portions like so: (4/6/)(97)
. I've had success so far for certain combinations only with something like this:
^\S*\s?(\d\d?/\d\d?/)(\d\d\d?\d?)\s?\S*
Could somebody please point me in the right direction?
Edit:
To make the problem simpler I tried to get a match for the entire date using the following expression: ^.*(\d\d?/\d\d?/\d\d\d?\d?).*
(the matcher expects that the expression match the entire string). Applied to the string "10/4/97 00:08 di"
the match returned is "0/4/97"
(maybe the matcher isn't the greatest ever built...). Could the regex string somehow be modified to ensure that the matcher returns all of the date?
(Thanks to SilentGhost for the editing).