def dashrepl(matchobj): if matchobj.group(0) == '-': return ' ' else: return '-'re.sub('-{1,2}', dashrepl, 'pro----gram-files')re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
本文共 253 字,大约阅读时间需要 1 分钟。
def dashrepl(matchobj): if matchobj.group(0) == '-': return ' ' else: return '-'re.sub('-{1,2}', dashrepl, 'pro----gram-files')re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
转载于:https://www.cnblogs.com/lanhoo/p/9709335.html