我有一个字符串,在swift中有新行,如下所示:
如何从该字符串中删除所有时间戳(11.03.2016 22:46:16)?
最简单的方法是将字符类与锚点相结合:
^[d. :]+(.+)
# anchor it to the beginning of the line
# only digits, spaces, dots and a colon allowed
# one or more times
# the (.+) brings you down the line
这里只带第一个被俘的小组
请在regex101.com上查看此方法的演示
对于您的情况,最简单的方法可以是使用以下regex进行搜索,并用empty string
进行替换。
Regex:^[d.: ]+:
并替换为empty string
。
Regex101演示
错误匹配最少的最准确的解决方案是:
^d{2}.d{2}.d{4} d{2}.d{2}.d{2}:
您还需要使用regex多行和全局标志。