Regex to match mm/dd/yyyy hh:mm:ss AM or PM

后端 未结 5 1262
逝去的感伤
逝去的感伤 2021-01-22 16:57

I have a program that creates information for a time stamp, the time stamp has to match the following format: MM/DD/YYYY HH:MM:SS AM or PM

For example:

5条回答
  •  无人共我
    2021-01-22 17:23

    This regex should work for you for validation of your inputs:

    ^\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d{1,2}:\d{1,2} [AP]M\z
    

    RegEx Demo

    This will validate either of these inputs lines:

    10/22/2016 9:15:32 PM
    9/9/2016 9:9:5 AM
    

提交回复
热议问题