默认字符串为:
strings123[abc123def456]strings456
为数字添加标记:
strings[abc<span>123</span>def<span>456</span>]strings
答案 0 :(得分:2)
按此搜索:
(\d+)
并替换为:
<span>\1</span>
示例来源:
import re
regex = r"(\d+)"
test_str = "strings[abc123def456]strings"
subst = "<span>\\1</span>"
result = re.sub(regex, subst, test_str, 0)
if result:
print (result)