Posted by Mitja Trampus on 10/11/05 01:50
BernieH wrote:
> I need a regex which will extract the year only from a variety of date
> strings such as -
>
> April 8, 2000
> 13 May 1999
> April 1999
> 1999
> 20050908 (yyyymmdd format)
>
> The year will always be either the 1st 4 or the last 4 characters of the
> string.
Then why regexes? Just cut off the first 4 and the last 4
characters, then see if any of them is a valid year (i.e.,
convert them to int and check something like 1900 < year <
2010).
Navigation:
[Reply to this message]
|