【问题标题】:ant replaceregex replace multilineant replaceregex 替换多行
【发布时间】:2012-04-22 05:06:01
【问题描述】:

我需要替换文件中的多行字符串,如下所示:

startString
bla bla bla
...
endString

由蚂蚁替换正则表达式。 蚂蚁代码:

    <copy file="${file}" tofile="${newFile}" overwrite="true">
        <filterchain>
            <replaceregex pattern="startString(.+)endString" replace="zzz" flags="gmi" byline="true"/>
        </filterchain>      
    </copy>

如果替换文本为单行 - 一切正常,但当文本为多行时 - replaceregex 不起作用。 我应该在我的代码中修复什么?

【问题讨论】:

    标签: ant


    【解决方案1】:

    您需要进行一些更改。您有几个设置建议应将每一行输入视为单独的输入行,即byline 属性和m 标志。在下文中,我删除了这些并添加了 s 标志,它将输入文件视为单行输入:

    <replaceregex pattern="startString(.+?)endString" replace="zzz"
        flags="gis" byline="false"/>
    

    还要注意在正则表达式中添加了?,这使得通配符不会贪婪,以防您要匹配多个匹配项。

    蚂蚁ReplaceRegExp 文档了解更多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 2012-06-20
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 2010-10-11
      相关资源
      最近更新 更多