re.sub(r'.d+.',r'.','ab.12.c')
#or
re.sub(r'.d+.',r'.','ab.12.c')
给ab.c
,而
re.sub(r'.d+.',r'.','ab.12.c')
#or
re.sub(r'.d+.',r'.','ab.12.c')
给ab\.c
.
前者给出了我想要的结果,但.
不应该像后者那样在正则表达式中转义吗?
似乎问题出在替换字符串上。为什么那个点不应该 逃脱?–李
啊哈,那个点在替换模式中,它不在正则表达式中。