names=c("Ajay","V ijay","Ra jay ", " Jayesh")
grepl("jay",names)
## [1]  TRUE  TRUE  TRUE FALSE
gregexpr(pattern ='jay',names)
## [[1]]
## [1] 2
## attr(,"match.length")
## [1] 3
## attr(,"useBytes")
## [1] TRUE
## 
## [[2]]
## [1] 4
## attr(,"match.length")
## [1] 3
## attr(,"useBytes")
## [1] TRUE
## 
## [[3]]
## [1] 4
## attr(,"match.length")
## [1] 3
## attr(,"useBytes")
## [1] TRUE
## 
## [[4]]
## [1] -1
## attr(,"match.length")
## [1] -1
## attr(,"useBytes")
## [1] TRUE
grep("jay",names)
## [1] 1 2 3
grep("jay",names,value = T)
## [1] "Ajay"    "V ijay"  "Ra jay "
# 
# grep(value = FALSE) returns a vector of the indices of the elements of x that yielded a match (or not, for invert = TRUE. This will be an integer vector unless the input is a long vector, when it will be a double vector.
#                                                                                                
#                                                                                                grep(value = TRUE) returns a character vector containing the selected elements of x (after coercion, preserving names but no other attributes).
#                                                                                                
#                                                                                                grepl returns a logical vector (match or not for each element of x).