I thought sub() function only replace the first time it found with a matched pattern.
However, in this example, it seems the sub() function replaced all the matched patterns. Can someone explain it?
awards <- c("Won 1 Oscar.",
"Won 1 Oscar. Another 9 wins & 24 nominations.",
"1 win and 2 nominations.",
"2 wins & 3 nominations.",
"Nominated for 2 Golden Globes. 1 more win & 2 nominations.",
"4 wins & 1 nomination.")
sub(".*\\s([0-9]+)\\snomination.*$", "\\1", awards)
Outcome :
[1] "Won 1 Oscar." "24" "2" "3" "2"
[6] "1"
I expect the Outcome will be:
[1] "Won 1 Oscar." "24" "1 win and 2 nominations.",
"2 wins & 3 nominations.",
"Nominated for 2 Golden Globes. 1 more win & 2 nominations.",
[6]"4 wins & 1 nomination."