I need to identify a hour in a string in a Regex. The rules are the following:
- The hour is in the format of
%mor%h:%m(by%xI meanxxorx); - The hour should be till
31:59; - Should NOT pass strings like
000,25:545;:12;
So, my actual variant of Regex is (with ExplicitCapture option, I verify it here):
((?<hours>([012]*[0-9])|([3]*[01]))\:)*(?<minutes>[0-5]*[0-9])
The problem is that I don’t achieve to “limit” this string ($myregex^, surprisingly, stopped detecting a valid string). Any idea why?
Try this:
You have some problems with your regex. Mostly, you’re using
*where you shouldn’t. This opens the door to many errors. For example, it matches the string"0010203333333".