import re
 
# 将匹配的数字乘以 2
def double(matched):
    value = int(matched.group('value'))
    return str(value * 2)
 
s = 'A23G4HFD567'
print(re.sub('(?P<value>\d+)', double, s))

 ?P<value>的意思就是命名一个名字为value的组,匹配规则符合后面的/d+

相关文章:

  • 2022-12-23
  • 2021-11-03
  • 2021-11-22
  • 2021-10-29
  • 2021-07-01
  • 2021-08-01
  • 2021-06-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案