"abc665abc12" -> "abc665abc", "12"
"abc665abc 182" -> "abc665abc", "182"
"abc665abc0" -> "abc665abc", "0"
Thank you!
< pre>> x = c(“abc665abc12”, “abc665abc 182”, “abc665abc0”)
> strsplit(x, “(?<=[A-Za-z])\\s*(?=\ \d+$)", perl = TRUE)
[[1]]
[1] “abc665abc” “12”
[[2]]
[ 1] “abc665abc” “182”
[[3]]
[1] “abc665abc” “0”
How to Split a string containing numbers (unknown digits) into two strings-the number and the rest of the string. Please note that there may be other numbers in the string that should not be affected. For example:
p>
"abc665abc12" -> "abc665abc", "12"
"abc665abc 182" -> "abc665abc", "182"
"abc665abc0" -> "abc665abc", "0"
Thank you!
You can also use strsplit
> x = c("abc665abc12", " abc665abc 182", "abc665abc0")
> strsplit(x, "(?<=[A-Za-z])\\s*(?=\\d+$)", perl = TRUE)
[[1]]
[1] "abc665abc" "12"
[[2]]
[1] "abc665abc" "182"
[[3]]
[1] "abc665abc" "0"