Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,我需要验证格式 -1D23H13M40S。(不区分大小写)
什么可以是正则表达式?
我试过了
myString.matches("[^0-9MHDS]*")
试试这个:
\d+D(\d|[01]\d|2[0-4])H(\d|[0-5]\d|60)M(\d|[0-5]\d|60)S
或者这个排除时间限制,例如24H,60M和60S:
24H
60M
60S
\d+D(\d|[01]\d|2[0-3])H(\d|[0-5]\d)M(\d|[0-5]\d)S