蚂蚁replaceregex取代多行 [英] ant replaceregex replace multiline

查看:141
本文介绍了蚂蚁replaceregex取代多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的文件替换多行字符串,像这样的:

I need replace multiline string in file, like this:

startString
bla bla bla
...
endString

蚂蚁replaceregex。
蚂蚁code:

by ant replaceregex. Ant code:

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

如果文本替换为单行 - 所有的作品正确的,但如果文字是多行 - replaceregex不起作用。
我应该在code修复么?

If text for replace is Single line - all works correct, but when text is multiline - replaceregex doesn't work. What I should fix in my code?

推荐答案

有一对夫妇,你需要做的改变。有一对夫妇的设置,您就表明输入的每一行,应考虑输入一个单独的线,是署名属性和 M 标记。在下面我已经删除了这些还增加它把输入文件输入的单行取值标记:

There are a couple of changes you need to do. There are a couple of settings you had suggesting that each line of input should be considered a separate line of input which are the byline attribute and the m flag. In the following I have removed those and also added the s flag which treats the input file a single line of input:

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

另外要注意在正则表达式中加入的,这使得非通配符贪婪万一你要匹配多次出现。

Also note the addition of the ? in the regex, this makes the wildcard non greedy in case you have multiple occurrences you want to match.

查看

蚂蚁 ReplaceRegExp 文档了解更多。

这篇关于蚂蚁replaceregex取代多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆