R grep: is there an AND operator?

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

Leave a Comment