删除第二个冒号后的文本 [英] Remove text after second colon
本文介绍了删除第二个冒号后的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要删除第二个冒号之后的所有内容.我有几种日期格式,需要使用相同的算法进行清理.
I need to remove everything after the second colon. I have several date formats, that need to be cleaned using the same algorithm.
a <- "2016-12-31T18:31:34Z"
b <- "2016-12-31T18:31Z"
我尝试对两个列组进行匹配,但似乎无法找到如何删除第二个匹配组.
I have tried to match on the two column groups, but I cannot seem to find out how to remove the second match group.
sub("(:.*){2}", "", "2016-12-31T18:31:34Z")
推荐答案
可以使用的正则表达式:(:[^:]+):.*
A regex you can use: (:[^:]+):.*
您可以查看:regex101 并使用类似
which you can check on: regex101 and use like
sub("(:[^:]+):.*", "\\1", "2016-12-31T18:31:34Z")
[1] "2016-12-31T18:31"
sub("(:[^:]+):.*", "\\1", "2016-12-31T18:31Z")
[1] "2016-12-31T18:31Z"
这篇关于删除第二个冒号后的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文