Skip to content
Prev 336689 / 398513 Next

Extracting everything between two symbols in a string

Hello,

I have a vector containing some names. I want to extract the title on 
every row, basically everything between the ", " (included the white 
space) and "."

     > head(combi$Name)
     [1] "Braund, Mr. Owen Harris"
     [2] "Cumings, Mrs. John Bradley (Florence Briggs Thayer)"
     [3] "Heikkinen, Miss. Laina"
     [4] "Futrelle, Mrs. Jacques Heath (Lily May Peel)"
     [5] "Allen, Mr. William Henry"
     [6] "Moran, Mr. James"

I suppose grep with the argument `value = TRUE` might come useful but I 
have difficulties on find the right regular expressions to accomplish my 
needs.

     combi$Title <- grep("", combi$Name, value = TRUE)

Many thanks,

Gianluca