问候所有,
我不确定这是否可行,但我想在正则表达式替换中使用匹配的组来调用变量.
a = 'foo'
b = 'bar'
text = 'find a replacement for me [[:a:]] and [[:b:]]'
desired_output = 'find a replacement for me foo and bar'
re.sub('\[\[:(.+):\]\]',group(1),text) #is not valid
re.sub('\[\[:(.+):\]\]','\1',text) #replaces the value with 'a' or 'b', not var value
Run Code Online (Sandbox Code Playgroud)
想法?
是否有可能避免将其放在每一页?
# -*- coding: utf-8 -*-
Run Code Online (Sandbox Code Playgroud)
我真的很喜欢Python默认这个.提前致谢!