I would like to extract the last set of digits from a string without doing this.
"sdkjfn45sdjk54()ad"
str_remove("sdkjfn45sdjk54()ad","[:alpha:]+$")
[1] "sdkjfn45sdjk54()"
str_remove(str_remove("sdkjfn45sdjk54()ad","[:alpha:]+$"), "\\(")
[1] "sdkjfn45sdjk54)"
str_remove(str_remove(str_remove("sdkjfn45sdjk54()ad","[:alpha:]+$"), "\\("), "\\)")
[1] "sdkjfn45sdjk54"
str_extract(str_remove(str_remove(str_remove("sdkjfn45sdjk54()ad","[:alpha:]+$"), "\\("), "\\)"), "\\d+$")
[1] "54"
because the patterns are uncertain. I am aware that stringi has a str_extract_from_last function but I need to stick to base R or stringR.
Thanks!