I would use str_match from stringr : "str_match extracts the capture groups formed by () from the first match. It returns a character matrix with one column for full match and one column for each group. Ref
str_match(my.string, paste(left.border, '(.+)', right.border, sep=''))[,2]
The above code creates a regular expression with paste that combines a capture group (.+) That captures 1 or more characters with left and right borders (no spaces between lines).
One match is assumed. So, [,2] selects the second column from the matrix returned by str_match .
source share