-3

I have an array of strings, and want to find a singular string in it that contains a date. The date contains the format "MM/DD/YY", but could be any date at all. I want to do something to the effect of

arr.find(/\d\d/\d\d/\d\d/);

The issue is, using a "/" in the regex expression causes the expression to end. How could I write a regex expression in Javascript that could find a string of any date in this format?

1 Answers1

0

To use literal slashes in a regex, just escape them with a backslash (\). Also, find takes a predicate function, not a regex pattern. The following code will do what you want:

arr.find(el => el.match(/\d\d\/\d\d\/\d\d/));
scatter
  • 903
  • 7
  • 24