I\'m trying to parse a user input string for duration (into seconds) with Javascript.
Here are some example inputs that I\'d like to be able to deal with:
You can use optional substrings in the regex to match any combination as you describe:
/(\d+)\s*d(ays?)?\s*(\d+)\s*h(ours?)?\s*(\d+)\s*m(in(utes?)?)?/
This requires at least a d, h, and m but accepts common shortenings.
d
h
m