0
Follow
2
View

java - regex pattern matching days, hours, minutes, seconds

d510423336 注册会员
2023-01-26 02:46

You can use

\d+\s*(?:day|hour|minute|second)s?(?:\s*,\s*\d+\s*(?:day|hour|minute|second)s?)*

See the regex demo

Details:

  • \d+\s*(?:day|hour|minute|second)s? - one or more digits, zero or more whitespaces, day or hour or minute or second and then an optional s char
  • (?:\s*,\s*\d+\s*(?:day|hour|minute|second)s?)* - zero or more sequences of a comma enclosed with zero or more whitespaces and then the same pattern as above.