Incorrect regular expression

Hello,
I've got a problem with underlined regular expression ".*srch.*\ [^brand|^dsa]". How can i write it correctly?
In this expression i want the condition: field campaign must contain "srch" and doesn`t contain "dsa" or "brand".

  SVOD_TVOD <-
  read.csv(xxxxxxxxxxxxxxxxxxxxxxxxxxx\\SVOD_TVOD.csv', sep = ";", encoding = 'UTF-8') %>% 
   mutate(campaign_type = case_when(
    grepl(".*brand.*", campaign, ignore.case = T) ~ "brand",
    grepl(".*dsa.*", campaign, ignore.case = T) ~ "dsa",
    grepl(".*dynrem.*", campaign, ignore.case = T) ~ "dynrem",
    grepl(".*net.*", campaign, ignore.case = T) ~ "net",
    grepl(**".*srch.*\ [^brand|^dsa]"**, campaign, ignore.case = T) ~ "srch_v1",
    TRUE ~ "others")) %>% 
  View()

Rather than trying to do that in a single regex, I would grepl for srch and !grepl for brand or dsa. That is, in syntactically incorrect form

 grepl("srch") & !grepl("brand|dsa")
1 Like

@FJCC Thank you, it works
I used:
grepl(".srch.", campaign, ignore.case = T) & !grepl(".brand|dsa|k50.", campaign, ignore.case = T) ~ "just_srch",

This topic was automatically closed 21 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.