用值后跟数字替换文件中的文本

时间:2015-11-07 18:16:36

标签: python regex ansible

我尝试使用replace模块替换配置文件中的端口号。通常可以通过以下方式完成:

replace: dest=config.file regexp='(.*)8080(.*)$' replace='\18081\2'

但它会导致问题,因为它试图匹配反向引用18081。

我已尝试将\1替换为${1},但它无效。

1 个答案:

答案 0 :(得分:2)

我成功了:

replace: dest=config.file regexp='(.*)8080(.*)$' replace='\g<1>8081\2'
相关问题