如何替换 Ant 中某些文本行中的反斜杠 [英] how to replace a backslash in some lines of a text in Ant

查看:24
本文介绍了如何替换 Ant 中某些文本行中的反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

<replaceregexp byline="true" flags="g" file="${someFIle}"
              match = "[\\]"
              replace = "/"/>

我可以很容易地用/替换所有的 \.

I can easily replace all the \ with /.

但是

假设文本是:

Other A\B\C
Some C\D\E
Other ...
Other ...
...

如何将带有前缀Some"的第二行中的/"替换为/",而不是其他行:

How to replace the "\" with "/" in the second line which has prefix "Some", but not other lines:

Other A\B\C
Some C/D/E
...

推荐答案

您的问题不能仅仅通过一个正则表达式来解决.你需要做一些更复杂的事情.

Your problem cannot be merely solved by a single regex. You need to do something more complex.

1) 仅读取具有指定前缀的属性并将它们保存到变量中.这可以通过 propertyregex 来完成.

1) Read properties only with the specified prefix and save them to variable. This can be done with propertyregex.

2) 读取所有其他属性并将它们保存在某处.

2) Read all other properties and save them somewhere.

3) 在包含前缀的属性中用您想要的任何内容替换 \.

3) Replace \ with whatever you want in the properties which contain the prefix.

4) 将带有不带前缀的属性的修改后的属性写入替换原始文件的文件中.

4) Write the modified properties with the properties without the prefix into a file replacing the original file.

5) 享受 :-)

尝试一一执行这些步骤.如果您仍有疑问,请告诉我.

Try to do these steps one by one. If you still have questions let me know.

这篇关于如何替换 Ant 中某些文本行中的反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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