Assume the following list:
string_test <- c("na-05-2021", "nk-31-2006", "NK-nk-1965", "NK-nk-89", "00-12-2005", "12-12-nk")
I would like to check if the strings respect the following date format: dd/mm/YYYY
If the day or the month is unknown, we admit to replace it by nk (upper or lower case).
So, the accepted strings in our example are: "na-05-2021", and "NK-nk-1965".
The other are not accepted.
I did the following regex but the returned results are not what i expected:
#install.packages("stringr")
library(stringr)
result <- str_detect(string_test , "/^(nk|NK|(0[1-9]|[12]/d|3[01]))+(-)+(nk|NK|0[1-9]|1[0-2])(-)+(1|2)+(0|9)+[0-9]+[0-9]/", negate = TRUE)
I think it's a problem with the regex but i tested it in https://regexr.com/ and it works as expected.