I have a set of files with names like this:
01990205abc.dat
20200304abc.dat
20210506abc.csv
My goal is to match the last two strings, but not the first string. I used this pattern: ^(2020)|(2021)[0-9]{4}abc.(csv)|(dat)$ and this code:
files <- list.files(path = "mirror", pattern = "^(2020)|(2021)[0-9]{4}abc.(csv)|(dat)$")
print(files)
matches all three files, instead of just the last two. My expectation was that
- (2020)|(2021)would match one of the years, but not- 0199.
- [0-9]{4}would match exactly four digits, then- abc, followed by one or the other file extensions.
 
     
    