Yet another post on negative lookbehind in regex in R but I can't find what I'm doing wrong here.
I have these strings:
test <- c("a %in% c('b', 'e')" , "case_when(a %in% c('b', 'e'))", "hello")
I want to detect which strings contain a %in%
without being preceded by a case_when(
. I can find which ones contain a case_when(
and then a %in%
with this regex:
grepl("(?=.*case\\_when\\()(.*%in%)", test, perl = TRUE)
#> [1] FALSE TRUE FALSE
So I just need to negate this lookbehind and I thought replacing =
by <!
was enough but apparently not:
grepl("(?<!case\\_when\\()(.*%in%)", test, perl = TRUE)
#> [1] TRUE TRUE FALSE
The expected output is TRUE FALSE FALSE
. What am I doing wrong?