0

I have a regualar expression here that matches a certain dates but not perfect:

/[1-2][0-9][0-9][0-9][/-][0-1][0-9][/-][0-3][1-9]/g

Matches:

2003/10/05 2003-10-05 1999/05/02 1970-12-29

Basically according to system time Epoch (reference date) which is I believe started from 1 January 1970 upto the current date.

In this case, how do I capture only those numbers ranging from 1970-2017 and for months: 01-12 and days: 01-31?

Anyone can help me and explain how to do it in regex?

Thanks!

  • 2
    `(19[7-9]\d|200\d|201[0-7])` is one way to match the year range. But why do you want to do it all with regex? Allowing for the fact that different months have different numbers of days makes for a pretty complicated regex even before you restrict the allowable years. – nnnnnn Nov 20 '17 at 02:03
  • 1
    I agree with @nnnnnn I would personally skip all the regex – Lilith Nov 20 '17 at 02:22
  • 1
    Do you seriously want to write code that needs to be updated every year? – CAustin Nov 20 '17 at 02:29
  • I got it. Don't worry I am just practicing regex here. I got the idea from nnnnn thanks! –  Nov 20 '17 at 03:14

0 Answers0