I have a list of duration times formatted like this:

```
['PT1H38M55S', 'PT25M28S', 'PT2H26S', ...]

```

I tried such grouping:

```
import re
re.search('PT([0-9]+|)H?([0-9]+|)M?([0-9]+|)S?', x).group(1, 2, 3)

```

where x is any element from the list, because I want a time() format from it:

```
from datetime import time
def parse_duration(x):
    HMS = re.search('PT([0-9]+)H([0-9]+)M([0-9]+)S', x).group(1, 2, 3)
    return time(int(HMS[0]), int(HMS[1]), int(HMS[2]))

```

But when there is no match, the code breaks.

Is there a solution to fill unmatched search with zero (for example) or another attempt would be easier?

I've found such method, but I couldn't apply it to my case:
[How to ignore unmatched group in a string in re python?](https://stackoverflow.com/questions/46989264/how-to-ignore-unmatched-group-in-a-string-in-re-python)