我不知道這是可能的,但我想使用匹配的組正則表達式替換調用變量。
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
想法?
ha!不是真的。熟悉py,perl和php - 沒有任何主人。感謝您的幫助:) – netricate