如何将包含数字(未知位数)的字符串拆分为两个字符串 – 数字和字符串的其余部分.请注意,字符串中可能存在其他不应受影响的数字.例如:
"abc665abc12" -> "abc665abc","12" "abc665abc 182" -> "abc665abc","182" "abc665abc0" -> "abc665abc","0"
谢谢!
解决方法
您也可以使用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"