正则表达式,将匹配的内容替换为加了新的内容

#! /usr/bin/env python
# -*- coding: utf-8 -*-#


import re

s = "你好2021"
content = re.sub(r"(\S+?)(\d+)", r"**\1** ##\2##", s)
print(content)

image

posted @ 2021-08-12 16:08  不能说的秘密  阅读(75)  评论(0编辑  收藏  举报