R grep: is there an AND operator?

前端 未结 4 1116
有刺的猬
有刺的猬 2020-11-30 06:00

Suppose I have the following data frame:

User.Id    Tags
34234      imageUploaded,people.jpg,more,comma,separated,stuff
34234      imageUploaded
12345      p         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 06:49

    Thanks to this answer, this regex seems to work. You want to use grepl() which returns a logical to index into your data object. I won't claim to fully understand the inner workings of the regex, but regardless:

    x <- c("imageUploaded,people.jpg,more,comma,separated,stuff", "imageUploaded", "people.jpg")
    
    grepl("(?=.*imageUploaded)(?=.*people\\.jpg)", x, perl = TRUE)
    #-----
    [1]  TRUE FALSE FALSE
    

提交回复
热议问题