This solution is strictly constrained by the data provided in which no more than three continuous files ending in the same letter occur.

```
filelist <- c("L1_0101_0601_A", "L1_0101_0603_A", "L1_0101_0605_B",
"L1_0101_0608_B", "L1_0101_0610_C", "L1_0101_0612_C",
"L1_0101_0615_A", "L1_0101_0617_A", "L1_0101_0619_A",
"L1_0101_0622_B", "L1_0101_0624_B", "L1_0101_0626_C",
"L1_0101_0629_C")
pat <- "^L1_\\d{4}_\\d{4}_"
# only last character is used
(shortlist <- gsub(pat,"",filelist))
#> [1] "A" "A" "B" "B" "C" "C" "A" "A" "A" "B" "B" "C" "C"
# find the index locations of sequential occurrences
(runs <- rle(shortlist))
#> Run Length Encoding
#> lengths: int [1:6] 2 2 2 3 2 2
#> values : chr [1:6] "A" "B" "C" "A" "B" "C"
# find the indexes locations of the third occurrence
(drops <- cumsum(runs$lengths)[which(runs$lengths > 2)])
#> [1] 9
# use this to subset out excess occurrence
(pruned <- filelist[-9])
#> [1] "L1_0101_0601_A" "L1_0101_0603_A" "L1_0101_0605_B" "L1_0101_0608_B"
#> [5] "L1_0101_0610_C" "L1_0101_0612_C" "L1_0101_0615_A" "L1_0101_0617_A"
#> [9] "L1_0101_0622_B" "L1_0101_0624_B" "L1_0101_0626_C" "L1_0101_0629_C"
# wrap in a function
trim_to_two <- function(x) {
runs = rle(gsub("^L1_\\d{4}_\\d{4}_","",x))
return(cumsum(runs$lengths)[which(runs$lengths > 2)] * -1)
}
(pruned <- filelist[trim_to_two(filelist)])
#> [1] "L1_0101_0601_A" "L1_0101_0603_A" "L1_0101_0605_B" "L1_0101_0608_B"
#> [5] "L1_0101_0610_C" "L1_0101_0612_C" "L1_0101_0615_A" "L1_0101_0617_A"
#> [9] "L1_0101_0622_B" "L1_0101_0624_B" "L1_0101_0626_C" "L1_0101_0629_C"
# modify input to introduce a second repetition of three
filelist <- c("L1_0101_0601_A", "L1_0101_0603_A", "L1_0101_0605_A",
"L1_0101_0608_B", "L1_0101_0610_C", "L1_0101_0612_C",
"L1_0101_0615_A", "L1_0101_0617_A", "L1_0101_0619_A",
"L1_0101_0622_B", "L1_0101_0624_B", "L1_0101_0626_C",
"L1_0101_0629_C")
(pruned <- filelist[trim_to_two(filelist)])
#> [1] "L1_0101_0601_A" "L1_0101_0603_A" "L1_0101_0608_B" "L1_0101_0610_C"
#> [5] "L1_0101_0612_C" "L1_0101_0615_A" "L1_0101_0617_A" "L1_0101_0622_B"
#> [9] "L1_0101_0624_B" "L1_0101_0626_C" "L1_0101_0629_C"
```

Created on 2023-01-16 with reprex v2.0.2