在Java或ANT下的regexp中输出换行符

时间:2011-08-19 11:44:45

标签: java regex ant replace newline

我有调用replaceregexp任务的ant目标

<target name="regexp.replace">
    <replaceregexp file="${file.temp}"
                   match="(.*)"
                   replace="first operation on \1  second operation on \1"
                   byline="true"/>
</target>

file.temp是

A1
A2

期望的输出是

first operation on A1
second operation on A1
first operation on A2
second operation on A2

要在ant replaceregexp参数中插入新行char以生成所需输出的内容?

 replace="first operation on \1 %NEW_LINE% second operation on \1"

1 个答案:

答案 0 :(得分:16)

以下适用于我:

<replaceregexp file="test.txt"
               match="(.*)"
               replace="first operation on \1${line.separator}second operation on \1"
               byline="true"/>
相关问题