4
>>> re.sub(r'(\d+)', r'\1' * 2, 'test line 123')
給
'test line 123123'
是有辦法讓它給
'test line 246'
?
float()
強制不起作用:
>>> re.sub(r'(\d+)', float(r'\1') * 2, 'test line 123')
could not convert string to float: \1
也不eval
或exec
。
I'd've標記您既作爲公認的答案。 – Adobe