假设我的输入字符串是以下之一:
2015-05-13T09:32:59.771Z
2015-05-13T09:32:59.7713Z
2015-05-13T09:32:59.77133Z
2015-05-13T09:32:59.771999999999Z
2015-05-13T09:32:59.000Z
2015-05-13T09:32:59Z
但作为输出我总是需要:
2015-05-13T09:32:59.000Z
我需要什么正则表达式?
let pattern = ":[0-9]{2}(\.)?([0-9]{0,})?Z&"
答案 0 :(得分:0)
试试这个:(\.[0-9A-z]*)|(([0-9]{2}Z))
您也可以这样做(如果日期和时间长度始终相同):
var sample:NSString = "2015-05-13T09:32:59.771Z"
var substr = sample.substringToIndex(19)
sample = substr + ".000Z"
println(sample) // prints 2015-05-13T09:32:59.000Z