Java或ANT下的正则表达式中输出换行符

发布于 2024-11-30 13:18:40 字数 627 浏览 1 评论 0原文

的 ant 目标,

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

我有调用replaceregexp 任务file.temp

A1
A2

所需的输出是

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

插入什么作为新行字符以在 ant Replaceregexp 参数中生成所需的输出?

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

I have ant target that invokes replaceregexp task

<target name="regexp.replace">
    <replaceregexp file="${file.temp}"
                   match="(.*)"
                   replace="first operation on \1  second operation 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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一片旧的回忆 2024-12-07 13:18:40

以下对我有用:

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

The following works for me:

<replaceregexp file="test.txt"
               match="(.*)"
               replace="first operation on \1${line.separator}second operation on \1"
               byline="true"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文