时间跨度,正则表达式与天部分 [英] Timespan-Regex with Days-Portion
问题描述
我只是试着数百(如果不是几千......)正则表达式的可用来获得我想要的......但是没有一次成功。
I've just tried several hundreds (if not thousands...) of RegEx's available to get what I want... But none of them worked.
我只是在寻找一个正则表达式,它表示一个时间跨度 days.hours:分:秒
:
7.00:00:00将表示7天
I'm simply looking for a Regular expression, that represents a TimeSpan days.hours:minutes:seconds
:
7.00:00:00 would represent "7 Days"
这一次可悲的是不工作:
This one sadly doesn't work:
(\d\ 。D)(\d\d):(([0-6] [0])|([0-5] [0-9])):(([0-6] [0])| ([0-5] [1-9]))
推荐答案
这是因为你的正则表达式期待2位数天,你只有1位数。只要第一个数字可选的?
That's because your Regex pattern is expecting 2 digits for days and you only have 1 digit. Just make the first digit optional with ?
(\d?\d)\.(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9]))
或更好,但只使用+匹配一个或更多,因为这一模式仍然不匹配100天
or better yet just use + to match one or more because that pattern would still not match 100 days
(\d+)\.(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9]))
这篇关于时间跨度,正则表达式与天部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!