蚂蚁replaceregex取代多行 [英] ant replaceregex replace multiline
问题描述
我需要的文件替换多行字符串,像这样的:
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屋!