Julio Di Egidio writes:
> On Friday, 29 April 2022 at 09:50:08 UTC+2, Loris Bennett wrote:
>> Hi,
>>
>> If I do
>>
>> import re
>> pattern =
>> re.compile(r'(?P\d*)(-?)(?P\d\d):(?P\d\d):(?P\d\d)')
>> s = '104-02:47:06'
>> match = pattern.search(s)
>> match_dict = match.groupdict('0')
>>
"Loris Bennett" writes:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> "Loris Bennett" writes:
>>>I thought that 'days' would default to '0'.
>>
>> It will get the value '0' if (?P\d*) does
>> /not/ participate in the match.
>>
>> In your case, it /does/ participate in the match,
>>
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> "Loris Bennett" writes:
>>I thought that 'days' would default to '0'.
>
> It will get the value '0' if (?P\d*) does
> /not/ participate in the match.
>
> In your case, it /does/ participate in the match,
> \d* matching the empty string.
>
>
Hi,
If I do
import re
pattern =
re.compile(r'(?P\d*)(-?)(?P\d\d):(?P\d\d):(?P\d\d)')
s = '104-02:47:06'
match = pattern.search(s)
match_dict = match.groupdict('0')
I get
match_dict
{'days': '104', 'hours': '02', 'minutes': '47', 'seconds': '06'}
However, if the string has no