Incorrect regular expression

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".

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

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, = T) & !grepl(".brand|dsa|k50.", campaign, = 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.