[英]Parsing a date format with regex
Using rubular http://rubular.com/ I'm trying to parse the hours minutes and seconds from a format 4H40M20S
我正在使用rubular http://rubular.com/尝试从格式4H40M20S
解析小时分钟和秒
So far I have this 到目前为止,我有这个
(\d*)H(\d*)M(\d*)S
Which works fine for 4H40M20S
but not for 40M20S
哪种适用于4H40M20S
但不适用于40M20S
What do I need to change to get it to work in this case? 在这种情况下,我需要进行哪些更改才能使其正常工作?
Looks like you're after something like: 看起来您正在追寻类似的东西:
([\d]+[HMS])+
If you want to capture each section seperately, then use: 如果要分别捕获每个部分,请使用:
([\d]+H)?([\d]+M)?([\d]+S)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.