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 strapply
function from the gsubfn
package to do this:
library(gsubfn)
data <- list("a sentence with citation (Ref. 12) and another (Ref. 13)", "single (Ref. 14)")
unlist(strapply(data,"(Ref. (\\d+))"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With