R grep regular expression using elements in a vector (FOLLOW UP)

后端 未结 3 1441
被撕碎了的回忆
被撕碎了的回忆 2021-01-26 23:58

Following up on this question, I have another example where I cannot use the accepted answer.

Again, I want to find each of the exact group elements in the

3条回答
  •  余生分开走
    2021-01-27 00:19

    + is a special character in regex. You will need "\+" to escape the special character.

    new_group <- gsub("\\+",replacement = "\\\\+",x =groups)
    

    Also, "|" in grep serves like "or".

    new_group1 <- paste0(new_group,collapse = "|")
    
    grep(pattern = new_group1,x = labs,value = T)
    

提交回复
热议问题