Ant不会替换同一行中的多个实例

时间:2016-06-13 14:19:20

标签: java regex replace ant

我正在使用replaceregexp替换文件中的特定匹配项。只要一行中有多个匹配,它就只替换该行的最后一个实例。

def adb(self, *args):
    process = subprocess.Popen(['adb.exe', args], stdout=subprocess.PIPE, shell=True)
    print(process.communicate())
    #return x.communicate(stdout)

请建议任何解决方案。

注意:我已尝试使用带有和没有'byline'的g,m,s标志,但它们不起作用。

1 个答案:

答案 0 :(得分:1)

由于您有no conditional replacement pattern support in Ant replaceregexp,因此只有一种可能的解决方案涉及两个步骤:

  • <replaceregexp file="mod1.js" match="f1(\.|\[&quot;)$lblTest(\.|&quot;\]|\[&quot;)" replace="f1\1lblTestNew\2" flags="g">将所有lblTest替换为lblTestNew文本
  • //Modified子字符串附加到字符串末尾,例如<replaceregexp file="mod1.js" match="(.*f1(\.|\[&quot;)lblTestNew(\.|&quot;\]|\[&quot;).*)" replace="\1 // Modified">