I have a string value, say, 102-105+106-10605-10605 -10610-10610+10613
. How can extract easily all values of three digits, all values of five digits. An additional task is to take into account the + or -
signs before the values. Say, extract all values of 5 digits that have sign -
before.
I know that there are some packages in R that enable you to do that. But I don't know how to do that exactly. I've tried various code, but unfortunately I failed each time.
From the vector I've mentioned I would like to extract all values of three digits and only five digits.
I used the code
str_extract_all(d, ("\\d{3}"))
And it gives me
[1] "102" "105" "106" "106" "106" "106" "106" "106" "106" "106".
But I want the following result "102" "105" "106"
. i.e. the code should not take into acconts 5-digits values and extract from them any three digits in a row.
In case of 5-digits query str_extract_all(d, ("\\d{5}"))
it gives me
[1] "10605" "10605" "10610" "10610" "10613" "10613" "10620".
This result is true.