Re: Match.groupdict: Meaning of default argument?

2022-05-03 Thread Loris Bennett
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') >>

Re: Match.groupdict: Meaning of default argument?

2022-05-03 Thread Loris Bennett
"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, >>

Re: Match.groupdict: Meaning of default argument?

2022-05-03 Thread Loris Bennett
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. > >

Match.groupdict: Meaning of default argument?

2022-04-29 Thread Loris Bennett
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