-1

I am looking for a js regex for datetime. The regex should allow: Only valid (optional, date validity will be checked later as well) date formmated dd/mm/yyyy, or the expressions: today, tomarrow, now, in x days/hours/years/minutes, if date is provided in one of the ways that dosent include "in x hours/minuts" or "now", the the time will be specified as well in the format hh:mm or hh:mm PM/AM or hh or hh PM/AM. If there is a regex that fit some of the rules but not all it will be ok as well. For example:

 now
 in 5 days 12 AM
 25/6/2020 14:05
 tomorrow 13
avivgood2
  • 227
  • 3
  • 19
  • @Utkanos I didn't intend to have any code written for me. In most cases for popular regexs such as date or email there is an already made for it somewhere. I did try my own regex but it works on conventional dates only dd/mm/yyyy hh:mm format. Didn't know how the expand it to the special cases as well. – avivgood2 May 30 '20 at 20:20
  • In that case you're asking for an off–site resource, which is off topic here. – RobG May 31 '20 at 01:05
  • @RobG what about https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression ? It asks for off site resources, it dosent provide any code, yet. It has over 3000 upvotes – avivgood2 May 31 '20 at 03:55
  • @avivgood2—thanks, I've voted to close it. It's been edited beyond recognition from the original question, which included code. But that was edited out many years ago. What you've posted is a request for someone else to write code for you, or point you to some other resource without any attempt at writing code yourself. – RobG May 31 '20 at 04:49

1 Answers1

-1

Did you mean something like?

let r = /(\d{1,2}\/\d{1,2}\/\d{4})|today|tomorrow|now|(in\s+\d+\s+(days|hours|years|minutes)(\s+\d{1,2}(:\d{2})?\s*(AM|PM))?)|\d{2}(:\d{1,2})?\s*(PM|AM)?/
r.test("please bring it to me tomorrow in 5PM okay?") // true
Denis
  • 132
  • 6