a=re.sub(r'hello (\w+), nihao \1', r'emma','hello sherry, nihao sherry') >>> a 'emma'#\1代表第一個分組的值即sherry,因?yàn)橛袃蓚€sherry,所以用\1可以指代第二個,這樣整個字符串被emma替換 示例4: 1 2 3 4 5 6 >>> a=re.sub('(\d{4})-(\d{2})-(\d{2})', r'\2-\3-...
www.dbjr.com.cn/article/1702...htm 2025-5-5