ant replaceregex替换多行
我需要替换文件中的多行字符串,如下所示:ant replaceregex替换多行,ant,Ant,我需要替换文件中的多行字符串,如下所示: startString bla bla bla ... endString 由ant replaceregex编写。 蚂蚁代码: <copy file="${file}" tofile="${newFile}" overwrite="true"> <filterchain> <replaceregex pattern="startString(.+)endString" re
startString
bla bla bla
...
endString
由ant replaceregex编写。
蚂蚁代码:
<copy file="${file}" tofile="${newFile}" overwrite="true">
<filterchain>
<replaceregex pattern="startString(.+)endString" replace="zzz" flags="gmi" byline="true"/>
</filterchain>
</copy>
如果replace的文本是单行-所有都正确,但是当文本是多行-replaceregex不工作。
我应该在代码中修复什么?您需要做一些更改。您有几个设置建议将每一行输入视为一个单独的输入行,它们是
byline
属性和m
标志。在下文中,我删除了这些内容,并添加了s
标志,该标志将输入文件视为一行输入:
<replaceregex pattern="startString(.+?)endString" replace="zzz"
flags="gis" byline="false"/>
还要注意,在正则表达式中添加了?
,这使得通配符在需要匹配多个匹配项的情况下不贪婪
见
有关更多信息,请参阅ant文档