首页 > 解决方案 > R:如何将字符串分成几部分

问题描述

标签: rstrsplit

解决方案


You can try with str_extract_all :

stringr::str_extract_all(x, '[A-Za-z_]+')[[1]]
[1] "CN"          "Shandong"    "Zibo"        "ABCDEFGHIJK" "IMG_HAS"

With base R :

regmatches(x, gregexpr('[A-Za-z_]+', x))[[1]]

Here we extract all the words with upper, lower case or an underscore. Everything else is ignored so characters like �\\00? are not there in final output.


推荐阅读