开发者

Output newline char in regexp under Java or ANT

开发者 https://www.devze.com 2023-03-29 01:05 出处:网络
I have ant target that invokes replaceregexp task <target name=\"regexp.replace\"> <replaceregexp file=\"${file.temp}\"

I have ant target that invokes replaceregexp task

<target name="regexp.replace">
    <replaceregexp file="${file.temp}"
                   match="(.*)"
                   replace="first operation on \1  second opera开发者_C百科tion on \1"
                   byline="true"/>
</target>

file.temp is

A1
A2

desired output is

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

What to insert as new line char for producing desired output in ant replaceregexp parameter?

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


The following works for me:

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

精彩评论

暂无评论...
验证码 换一张
取 消