我有这个字符串:

235072,testing,some252f4,14084-things224072,and,other2524,14084-thingies223552,testing,some/2wr24,14084-things


我想将字符串除以6位数字。即- 我要这个:

235072,testing,some2wg2f4,wf484-things
224072,and,other25wg4,14-thingies
223552,testing,some/2wr24,14084-things


我该如何使用正则表达式呢?以下内容不起作用(使用stringr包):

> blahblah <- "235072,testing,some252f4,14084-things224072,and,other2524,14084-thingies223552,testing,some/2wr24,14084-things"
> test <- str_split(blahblah, "([0-9]{6}.*)")
> test
[[1]]
[1] "" ""


我想念什么?

最佳答案

str_extract_all的替代方法。请注意,我已经使用.*?进行“非贪婪”匹配,否则.*会扩展以获取所有内容:

> str_extract_all(blahblah, "[0-9]{6}.*?(?=[0-9]{6}|$)")[[1]]
[1] "235072,testing,some252f4,14084-things"  "224072,and,other2524,14084-thingies"    "223552,testing,some/2wr24,14084-things"

关于r - 如何在R中的正则表达式中使用str_split?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49439692/

10-12 16:30