简体   繁体   中英

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

So far I have this

(\d*)H(\d*)M(\d*)S

Which works fine for 4H40M20S but not for 40M20S

What do I need to change to get it to work in this case?

Looks like you're after something like:

([\d]+[HMS])+

正则表达式可视化

Debuggex Demo


If you want to capture each section seperately, then use:

([\d]+H)?([\d]+M)?([\d]+S)

正则表达式可视化

Debuggex Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM