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