我希望将字符串拆分为向量和列表。如果有一个OR
或一个||
我想拆分成列表。如果有AND
or
&& split into a vector. With the word version I get it but not with the use of
| and
&`. 这是代码:
splitting <- function(x) {
lapply(strsplit(x, "OR|[\\|\\|]"), function(y){
strsplit(y, "AND|[\\&\\&]")
})
}
splitting("3AND4AND5OR4OR6AND7") ## desired outcome for all three
splitting("3&&4&&5||4||6&&7")
splitting("3&&4&&5OR4||6&&7")
这是期望的结果:
> splitting("3AND4AND5OR4OR6AND7")
[[1]]
[[1]][[1]]
[1] "3" "4" "5"
[[1]][[2]]
[1] "4"
[[1]][[3]]
[1] "6" "7"
如何正确设置此正则表达式?我在做什么不正确?