I try to write a regex for a date pattern (mm/dd/yyyy ; m/d/yy ; etc...) :
".*([0-9]+/[0-9]+/[0-9]+).*"
However for my usecase, the year can be omitted. In this case, I still want to match mm/dd. I tried to put the last group opional for that purpose:
".*([0-9]+/[0-9]+(/[0-9]+)?).*"
But it does not work with a full date pattern (R code below):
str = "hello 2/5/2017 123"
gsub(".*([0-9]+/[0-9]+(/[0-9]+)?).*", "\\1", str)
Result:
[1] "5/2017"
Any idea of what I am doing wrong ?