@@ -173,7 +173,7 @@ def group(self, *args):
173173
174174 def groups (self , default = None ):
175175 lst = []
176- for arg in range (1 , self .result .groupCount ):
176+ for arg in range (1 , self .compiled_regex .groupCount ):
177177 lst .append (self .__group__ (arg ))
178178 return tuple (lst )
179179
@@ -214,7 +214,7 @@ def string(self):
214214
215215 @property
216216 def lastgroup (self ):
217- return self .result .groupCount
217+ return self .compiled_regex .groupCount
218218
219219 @property
220220 def lastindex (self ):
@@ -357,9 +357,9 @@ def findall(self, string, pos=0, endpos=-1):
357357 result = tregex_call_exec (compiled_regex .exec , string , pos )
358358 if not result .isMatch :
359359 break
360- elif result .groupCount == 1 :
360+ elif compiled_regex .groupCount == 1 :
361361 matchlist .append (self .__sanitize_out_type (string [result .getStart (0 ):result .getEnd (0 )]))
362- elif result .groupCount == 2 :
362+ elif compiled_regex .groupCount == 2 :
363363 matchlist .append (self .__sanitize_out_type (string [result .getStart (1 ):result .getEnd (1 )]))
364364 else :
365365 matchlist .append (tuple (map (self .__sanitize_out_type , SRE_Match (self , pos , endpos , result , string , compiled_regex ).groups ())))
@@ -368,8 +368,8 @@ def findall(self, string, pos=0, endpos=-1):
368368 return matchlist
369369
370370 def __replace_groups (self , repl , string , match_result , pattern ):
371- def group (match_result , group_nr , string ):
372- if group_nr >= match_result .groupCount :
371+ def group (pattern , match_result , group_nr , string ):
372+ if group_nr >= pattern .groupCount :
373373 return None
374374 group_start = match_result .getStart (group_nr )
375375 group_end = match_result .getEnd (group_nr )
@@ -382,18 +382,18 @@ def group(match_result, group_nr, string):
382382 pos = repl .find (backslash , start )
383383 while pos != - 1 and start < n :
384384 if pos + 1 < n :
385- if repl [pos + 1 ].isdigit () and match_result .groupCount > 0 :
385+ if repl [pos + 1 ].isdigit () and pattern .groupCount > 0 :
386386 # TODO: Should handle backreferences longer than 1 digit and fall back to octal escapes.
387387 group_nr = int (repl [pos + 1 ].decode ('ascii' )) if self .__binary else int (repl [pos + 1 ])
388- group_str = group (match_result , group_nr , string )
388+ group_str = group (pattern , match_result , group_nr , string )
389389 if group_str is None :
390390 raise error ("invalid group reference %s at position %s" % (group_nr , pos ))
391391 result += repl [start :pos ] + group_str
392392 start = pos + 2
393393 elif repl [pos + 1 ] == (b'g' if self .__binary else 'g' ):
394394 group_ref , group_ref_end , digits_only = self .__extract_groupname (repl , pos + 2 )
395395 if group_ref :
396- group_str = group (match_result , int (group_ref ) if digits_only else pattern .groups [group_ref ], string )
396+ group_str = group (pattern , match_result , int (group_ref ) if digits_only else pattern .groups [group_ref ], string )
397397 if group_str is None :
398398 raise error ("invalid group reference %s at position %s" % (group_ref , pos ))
399399 result += repl [start :pos ] + group_str
@@ -477,7 +477,7 @@ def split(self, string, maxsplit=0):
477477 end = match_result .getEnd (0 )
478478 result .append (self .__sanitize_out_type (string [collect_pos :start ]))
479479 # add all group strings
480- for i in range (1 , match_result .groupCount ):
480+ for i in range (1 , pattern .groupCount ):
481481 groupStart = match_result .getStart (i )
482482 if groupStart >= 0 :
483483 result .append (self .__sanitize_out_type (string [groupStart :match_result .getEnd (i )]))
0 commit comments