I am trying to extract 'display2d...jpg
' in each string vector, but I am not sure how to do it efficiently. Is there a better way?
One way I did was to use the function, str_extract()
like this.
l1 <- "<p><strong>Which piece can be rotated to match the display figure?</strong></p>\n\n<p><strong><img alt=\"\" src=\"/bundles/pppp/files/display2d_12-2.jpg\" style=\"width: 256px; height: 256px;\" /></strong></p>\n"
l2 <- "<p><strong>Which piece can be rotated to match the display figure?</strong></p>\n\n<p><strong><img alt=\"\" src=\"/bundles/pppp/files/display2d_8-2.jpg\" style=\"width: 256px; height: 256px;\" /></strong></p>\n"
l3 <- c(l1,l2)
# grab everything in between display and jpg
inner <- str_extract(string = l3, pattern = "(?<=display).*(?=jpg)")
# then paste back display and jpg
paste0('display', inner, 'jpg')