I need to convert a string containing a special time format to a standard one, example: "1h2m3s40ms" -> "01:02:03:0040". The source string could contain any combination of hours, minutes, seconds or milliseconds, like "1h4s", "34m", "23h45s" etc. And this is where I need some help.
A basic regular expression that would validate the string where they all have a value is pretty easy, like this:
"[0-9]+h[0-9]+m[0-9]+s[0-9]+ms"
But how do you make the individual hours, minutes etc optional?
I tried something like this:
"([0-9]+h)?([0-9]+m)?([0-9]+s)?([0-9]+ms)?"
But that didn't pass my regexp tester, everything was permitted.
Please help a regexp noob :)