Q:

How to check does string contains start and end - date

I have an array of object that I need to iterate through. I'm trying to check that is contain the following string date : "7/2/2019 - 7/31/2019".
My issue is that my regex is not working :
const dateType = /(\d{4})([\/-])(\d{1,2})\2(\d{1,2})/;
I tried to filter trough this array of objects and check with a regex that current object.name string contain said string date but as before, my regex is problematic.
  const isMatch = this.state.selectedFilters.filter((filter) => 
     dateType.test(filter.name));

      if (isMatch) {
        // ...
      }

How to make my regex match this format of dates : "7/2/2019 - 7/31/2019"?
Thanks in advance for your help.

A:

Try this:
((0?[1-9])|(1[0-2]))\/((0?[1-9])|([12][0-9])|(3[01]))\/((\d{4})|(\d{2}))\s*-\s*((0?[1-9])|(1[0-2]))\/((0?[1-9])|([12][0-9])|(3[01]))\/((\d{4})|(\d{2}))

Here Is Demo

