How to split English letters, numbers and Chinese characters in R?

Viewed 114

I need to split the strings of mixture of Chinese/English/numbers (e.g., "123-321-中文.jpg" or "001-123你好.png") or extract the Chinese words in the strings using R. Any solution for that?

1 Answers

To extract the chinese words only, We could use str_extract: extracting all non latin characters with "[:alpha:]+":

library(stringr)

string <- c("123-321-中文.jpg", "001-123你好.png")

str_extract(string, "[:alpha:]+")

output:

[1] "中文" "你好"
Related