小编Joh*_*ith的帖子

在R中使用strsplit(),忽略括号中的任何内容

我试图strsplit()在R中使用基于逗号将字符串分解成碎片,但我不想在括号中拆分任何东西.我认为答案是正则表达式,但我正在努力使代码正确.

例如:

x <- "This is it, isn't it (well, yes)"
> strsplit(x, ", ")
[[1]]
[1] "This is it"     "isn't it (well" "yes)" 
Run Code Online (Sandbox Code Playgroud)

当我想要的是:

[1] "This is it"     "isn't it (well, yes)"
Run Code Online (Sandbox Code Playgroud)

regex r strsplit

14
推荐指数
2
解决办法
925
查看次数

标签 统计

r ×1

regex ×1

strsplit ×1