Grep seems to be βgreedyβ in the way it returns matches. Assuming I have the following data:
Sources <- c(
"Coal burning plant",
"General plant",
"coalescent plantation",
"Charcoal burning plant"
)
Registry <- seq(from = 1100, to = 1103, by = 1)
df <- data.frame(Registry, Sources)
If I execute grep("(?=.*[Pp]lant)(?=.*[Cc]oal)", df$Sources, perl = TRUE, value = TRUE), it returns
"Coal burning plant"
"coalescent plantation"
"Charcoal burning plant"
However, I only want to return an exact match, i.e. only where "coal" and "plant" occur. I do not want "coalescence", "plantation", etc. Therefore, for this I want to see only"Coal burning plant"
source
share