我有以下Python代码:
string = '[subscript=hello] this is some text [subscript=hi again]'
superscripts = re.findall(r'\[subscript=(.+?)\]', string)
print superscripts
它返回['hello', 'hi again']
,这是我想要的文本,但是,我宁愿它替换字符串,以便它返回<sub>hello</sub> this is some text <sub>hi again<sub>
,而不是返回这个。我知道我应该用回复sub()但我不确定如何使用它来正确地替换字符串。你知道吗
我该怎么做?谢谢。你知道吗
编辑:屏幕截图
使用反向引用
\1
,它引用模式中第一个参数中匹配的组:相关问题 更多 >
编程相关推荐