Why does my regex stops working when the end anchor ($) is preceeded by an optional caracter anchor (?)? For example
library(tidyverse
s <- '[S|s][EG|eg]?'
s2 <- '^[S|s][EG|eg]?$'
[1] TRUE TRUE
c('s','Seg') %>% str_detect(s2)
[1] TRUE FALSE
Wrapping the regex with [ ]
also did not work
s3 <- '^[[S|s][EG|eg]?]$'
c('s','Seg') %>% str_detect(s)
c('s','Seg') %>% str_detect(s3)
[1] TRUE FALSE