(?!) in stringr does not work as expected

library(tidyverse)
library(stringr)

df <- tibble::tribble(
  ~tch_id,  ~online_platform,
      105,          "Google",
      106,            "meet",
      107,            "Zoom",
      108,            "zoom",
      109,     "Google Meet",
      112, "Microsoft Teams",
      113,                NA
  )


# work
df %>%
   filter(
      str_detect(online_platform, regex("google|meet", ignore_case = TRUE))
   )
#> # A tibble: 3 x 2
#>   tch_id online_platform
#>    <dbl> <chr>          
#> 1    105 Google         
#> 2    106 meet           
#> 3    109 Google Meet

# does not work as expected, why?
df %>%
   filter(
      str_detect(online_platform, "(?!)google|meet")
   )
#> # A tibble: 1 x 2
#>   tch_id online_platform
#>    <dbl> <chr>          
#> 1    106 meet

Created on 2022-03-25 by the reprex package (v2.0.1)

typos
is (?i), not (?!)

df %>%
   filter(
      str_detect(online_platform, "(?i)google|meet")
   )

work now

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.