Reputation: 181
I want to parse a time expression string (has 4 groups: week(w), day(d), hour(h) and minute(m)). Some examples are:
I came up with this pattern:
([+-]{0,1})([0-9]+)w?\s?(0?[1-9]|[12][0-9]|3[01])d?\s?([01]?[0-9]|2[0-3])h?\s?([0-5][0-9])m?
But this pattern not work. Please help. Sorry for my english!
Upvotes: 1
Views: 176
Reputation: 3288
This is what I use for my validation:
^(?:(?:0?[0-9]|1[0-2]):[0-5][0-9]\s?(?:(?:[Aa]|[Pp])[Mm])?|(?:1[3-9]|2[0-3]):[0-5][0-9])$
It works for 24:00 and 12:00 format allowing capital am/pm.
Maybe it can help you in the right direction.
Upvotes: 0
Reputation: 67968
^([+-]?)([0-9]+)?w?\s*?(0?[1-9]|[12][0-9]|3[01])?d?\s*?([01]?[0-9]?|2[0-3])?h?\s*?([0-5]?[0-9])?m?$
Modified your regex.Works now.Might need more testing though.
See demo.
http://regex101.com/r/sB4kE6/4
Upvotes: 1