如何用匹配的转换替换重新匹配?

如何用匹配的转换替换重新匹配?,第1张

如何用匹配转换替换重新匹配?

使用功能进行替换

s = 'The struct-of-application and struct-of-world'p = re.compile('((w+-)+w+)')def replace(match):    return 'http://{}'.format(match.group())    #for python 3.6+ ...     #return f'http://{match.group()}'>>> p.sub(replace, s)'The http://struct-of-application and http://struct-of-world'>>>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5648445.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存