Search code examples
regexoracle-adf

Regular expression for time period


I am using jdev 12.2.1.0.0 and I am trying to validated an input field(String) with the "" in which i am try to enter period of time in formats shown below

  • 1h 40m 20s
  • 1h 40m
  • 2h 30s
  • 30m 20s
  • 30m
  • 30 (It will be considered as 30m)
  • 10s

So I need a regular expression which allow a user to enter the period of time in any given format also no need to consider the space between the unit (ie: 1h30m is also valid).


Solution

  • Here is a suggestion that matches all the cases you wanted:

    ((\d{1,2}h\s?)?(\d{1,2}m\s?)?(\d{1,2}s\s?)?)|\d{1,2}
    

    Demo on regex101