我正在使用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标志,但它们不起作用。
答案 0 :(得分:1)
由于您有no conditional replacement pattern support in Ant replaceregexp
,因此只有一种可能的解决方案涉及两个步骤:
<replaceregexp file="mod1.js" match="f1(\.|\[")$lblTest(\.|"\]|\[")" replace="f1\1lblTestNew\2" flags="g">
将所有lblTest
替换为lblTestNew
文本//Modified
子字符串附加到字符串末尾,例如<replaceregexp file="mod1.js" match="(.*f1(\.|\[")lblTestNew(\.|"\]|\[").*)" replace="\1 // Modified">
。