Q:

Java regular expression to check time format

I have a string which i need to validate for format -1D23H13M40S. (case insensitive)
What can be the regular expression??
I have tried
myString.matches("[^0-9MHDS]*") 

A:

Try this one:
\d+D(\d|[01]\d|2[0-4])H(\d|[0-5]\d|60)M(\d|[0-5]\d|60)S

Or this one to exclude time limits such as 24H, 60M and 60S:
\d+D(\d|[01]\d|2[0-3])H(\d|[0-5]\d)M(\d|[0-5]\d)S

