Given the following vector:
v = c("A/5 21171", "PC 175959", "STON/O2. 3101282", "113803", "373450")
How can extract the last 5 or 6 digits from each element? This the desired output:
v_processed = c("21171", "175959", "3101282", "113803", "373450")
My try:
v = unlist(strsplit(v, "^[^0-9]+"))
v[v == ""] = NA
v_processed = na.omit(v)
But that last snippet gives me this:
"5 21171" "175959" "2. 3101282" "113803" "373450"
I do not want that 5 in the first element, nor the "2." in the third one.
Thx.
3101282
is 7 digits. And trysub(".*?(\\d{5,6})$", "\\1", v)
(if you want101282
in fact, not3101282
)3101282
is 7 digits. Then I refer to the last bunch of digits, no matter they are 5, 6 or 7