2

this example from here (r- grepl to find multiple strings exists) helps me match combinations of words:

pat <- c("instance", "percentage", "element", "character")

longperl <- grepl(paste0("(?=.*", pat, ")", collapse=""), Text2, perl=TRUE)

However I'm trying to match the word table (along with other words) and using the above is also returning words that contain the pattern table, e.g., marketable. How do I force the grepl snippet to only include the whole word table and not where table is part of another word?

I've tried these without success:

pat <- c(" table", "instance", "percentage", "element", "character") # add literal space before `table`

pat <- c("\\stable", "instance", "percentage", "element", "character") # add whitespace regex before `table`
val
  • 1,629
  • 1
  • 30
  • 56

0 Answers0