正则表达式 – 按句子中的最后一个单词拆分列
发布时间:2020-12-13 21:52:57 所属栏目:百科 来源:网络整理
导读:YARQ(另一个正则表达式问题). 我如何将以下内容拆分为两列,确保最后一列包含句子中的最后一个单词,第一列包含其他所有单词. x - c("This is a test","Testing 1,2,3 Hello","Foo Bar","Random 214274(%*(^(* Sample","Some Hyphenated-Thing" ) 这样我最终得
YARQ(另一个正则表达式问题).
我如何将以下内容拆分为两列,确保最后一列包含句子中的最后一个单词,第一列包含其他所有单词. x <- c("This is a test","Testing 1,2,3 Hello","Foo Bar","Random 214274(%*(^(* Sample","Some Hyphenated-Thing" ) 这样我最终得到: col1 col2 this is a test Testing 1,3 Hello Foo Bar Random 214274(%*(^(* Sample Some Hyphenated-Thing
这看起来像是一个展望未来的工作.我们会找到空格,后面跟不是空格的东西.
split <- strsplit(x," (?=[^ ]+$)",perl=TRUE) matrix(unlist(split),ncol=2,byrow=TRUE) [,1] [,2] [1,] "This is a" "test" [2,] "Testing 1,3" "Hello" [3,] "Foo" "Bar" [4,] "Random 214274(%*(^(*" "Sample" [5,] "Some" "Hyphenated-Thing" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |