This function generates a regular expression for time based on the input format.

regex_time(format = "hh:mm")

Arguments

format

The format of the time. Possible values are:

  • "hh:mm": to generate "09:05".

  • "h:m": to generate "9:5".

  • "hh:mm:ss": to generate "09:05:00".

  • "h:m:s": to generate "9:5:0".

  • "hh:mm:ss AM/PM": to generate "09:05:00 AM".

  • "h:m:s AM/PM": to generate "9:5:0 AM".

Value

A regular expression.

Examples

regex_time("hh:mm")
#>                     hh:mm 
#> "^[0-2][0-9]:[0-5][0-9]$" 
regex_time("h:m")
#>                             h:m 
#> "^([1-2])?[0-9]:([1-5])?[0-9]$" 
regex_time("hh:mm:ss")
#>                                       hh:mm:ss 
#> "^([0-1]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$" 
regex_time("h:m:s")
#>                                                      h:m:s 
#> "^([0-9]|0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$" 
regex_time("hh:mm:ss AM/PM")
#>                                  hh:mm:ss AM/PM 
#> "^(1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm])$" 
regex_time("h:m:s AM/PM")
#>                                                              h:m:s AM/PM 
#> "^([0-9]|0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]) ?([AaPp][Mm])$"