@@ -173,7 +173,7 @@ def group(self, *args):
173
173
174
174
def groups (self , default = None ):
175
175
lst = []
176
- for arg in range (1 , self .result .groupCount ):
176
+ for arg in range (1 , self .compiled_regex .groupCount ):
177
177
lst .append (self .__group__ (arg ))
178
178
return tuple (lst )
179
179
@@ -214,7 +214,7 @@ def string(self):
214
214
215
215
@property
216
216
def lastgroup (self ):
217
- return self .result .groupCount
217
+ return self .compiled_regex .groupCount
218
218
219
219
@property
220
220
def lastindex (self ):
@@ -357,9 +357,9 @@ def findall(self, string, pos=0, endpos=-1):
357
357
result = tregex_call_exec (compiled_regex .exec , string , pos )
358
358
if not result .isMatch :
359
359
break
360
- elif result .groupCount == 1 :
360
+ elif compiled_regex .groupCount == 1 :
361
361
matchlist .append (self .__sanitize_out_type (string [result .getStart (0 ):result .getEnd (0 )]))
362
- elif result .groupCount == 2 :
362
+ elif compiled_regex .groupCount == 2 :
363
363
matchlist .append (self .__sanitize_out_type (string [result .getStart (1 ):result .getEnd (1 )]))
364
364
else :
365
365
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):
368
368
return matchlist
369
369
370
370
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 :
373
373
return None
374
374
group_start = match_result .getStart (group_nr )
375
375
group_end = match_result .getEnd (group_nr )
@@ -382,18 +382,18 @@ def group(match_result, group_nr, string):
382
382
pos = repl .find (backslash , start )
383
383
while pos != - 1 and start < n :
384
384
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 :
386
386
# TODO: Should handle backreferences longer than 1 digit and fall back to octal escapes.
387
387
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 )
389
389
if group_str is None :
390
390
raise error ("invalid group reference %s at position %s" % (group_nr , pos ))
391
391
result += repl [start :pos ] + group_str
392
392
start = pos + 2
393
393
elif repl [pos + 1 ] == (b'g' if self .__binary else 'g' ):
394
394
group_ref , group_ref_end , digits_only = self .__extract_groupname (repl , pos + 2 )
395
395
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 )
397
397
if group_str is None :
398
398
raise error ("invalid group reference %s at position %s" % (group_ref , pos ))
399
399
result += repl [start :pos ] + group_str
@@ -477,7 +477,7 @@ def split(self, string, maxsplit=0):
477
477
end = match_result .getEnd (0 )
478
478
result .append (self .__sanitize_out_type (string [collect_pos :start ]))
479
479
# add all group strings
480
- for i in range (1 , match_result .groupCount ):
480
+ for i in range (1 , pattern .groupCount ):
481
481
groupStart = match_result .getStart (i )
482
482
if groupStart >= 0 :
483
483
result .append (self .__sanitize_out_type (string [groupStart :match_result .getEnd (i )]))
0 commit comments