re.sub
. re.sub
( re.subn
) , str
. (, ) repl
, .
match
, , , callable
, , . :
class Replacer:
def __init__(self):
self.matchcnt = 0
def __call__(self, matchobj):
self.matchcnt += 1
return matchobj.group(0) + str(self.matchcnt)
re.sub
/re.subn
, Replacer()
repl
; matchcnt
, __call__
, ; , , , . sub
, , sub
.