例如,我有一个字符串:如何用匹配的转换替换重新匹配?
The struct-of-application and struct-of-world
随着re.sub
,它将替换预定义的字符串匹配。如何将匹配替换为匹配内容的转换?为了获得,例如:
The [application_of_struct](http://application_of_struct) and [world-of-struct](http://world-of-struct)
如果我写了一个简单的正则表达式((\w+-)+\w+)
,并尝试使用re.sub
,看来我不能用我作为替代的一部分匹配,更不用说编辑匹配的内容:
In [10]: p.sub('struct','The struct-of-application and struct-of-world')
Out[10]: 'The struct and struct'
@ KevinJ.Chase我将添加re.sub的结果很快 – KIDJourney
使用多行代码? – wwii
@wwii如何?搜索并替换? – KIDJourney