I have text with days, hours, minutes, in following format:
4 d. 12 h. 32 m.
7 h. 22 m.
3 d. 14 h.
Notice, that some of them may be apsent (e.g.: 3 d. 14 h.
doesnt contains minutes)
I want to capture digit in named groups, but do not capture the characters (d. h. m.). So finally i need to get result something like this map:
[
'days' => 4,
'hours' => 12,
'minutes' => 32,
]
This what i wrote: (?P<days>(\d+) d.)?(?P<hours>(\d+) h.)?(?P<minutes>(\d+) m.)?
Link: https://regex101.com/r/FERRnd/1
But it seems that there is some empty elements, and i have feeling that this is not best regular expression for this task. Is there any way to recieve only named params as digits and nothing else (no empty fields, no text like 12 h.
etc.)?
Many thanks!