How can I use grepl
to return exact matches only, but ignore semicolons? I may be poorly explaining what I want to do, so please see the minimal reprex below of what I'm trying to acheive:
#Define what I want to select
my_choice <- c("and")
my_words1 <- c("sand;sand;land") #Test 1
my_words2 <-c("and;and;and;bland")#Test 2
#Try to get selection with test 1:
> my_words1[grepl(my_choice, my_words1, fixed=TRUE)]
[1] "sand;sand;land"
#^----Not correct! Should return nothing
#Try with test 2:
> my_words2[grepl(my_choice, my_words2, fixed=TRUE)]
[1] "and;and;and;bland"
#^----Also not correct! should return "and;and;and"