I’m trying to parse an ISO 8601 duration with the following pattern I did:
P(\d+Y)?(\d+M)?(\d+D)?(\d+W)?T(\d+H)?(\d+M)?(\d+S)?
But the problem is it works on PT158M12S but not on PT12S158M. Is it possible to make the groups after P and the groups after T be in any order?
Try
(shorter version of Rohit’s answer)
However this does not prevent to repeat any group, e.g.
PT1M2M. You will have to check that afterwards.