-1

Write a regular expression for the following:

A regular expression that finds dates in files. Correct dates must be in the format DD-MM-YYYY and within the years 1900s and 2000s. No need to enforce the correct maximum number of days in a month. For example, within the following list: 10-02-2011 , 6-Feb-2016 , 8-5-2016 , 07-08-1966 , 32-05-2022

only 10-02-2011 and 07-08-1966 are valid dates.

A regular expression that accepts any of the following answers for the question “What are 5, 6 and 14?” numbers They’re numbers They are numbers

Luca
  • 55
  • 1
  • 7

1 Answers1

0

According to your question, the regex pattern must match any date between 1900 and 2000, is that correct? If it is that what you want, this is the pattern you need:

(3[0-1])|([0-2][0-9])-((0[0-9])|(1[0-2]))-(19\d{2})|2000

The year group will match any year from 1900 to 2000, let me know if you find any error on this pattern, or give me some entries that this pattern should've matched...

Hope I have helped!

s_bighead
  • 1,014
  • 13
  • 24