I’m looking for a gsub string that will return all matches of an expression, rather than just the last match. i.e.:
data <- list("a sentence with citation (Ref. 12) and another (Ref. 13)", "single (Ref. 14)")
gsub(".*(Ref. (\\d+)).*", "\\1", data)
Returns
[1] "Ref. 13" "Ref. 14"
so I’ve lost Ref. 12.
You can use the
strapplyfunction from thegsubfnpackage to do this: