how to replace a backslash in some lines of a text in Ant

一个人想着一个人 提交于 2019-12-11 05:39:37

问题


Using

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

I can easily replace all the \ with /.

But

Suppose the text is:

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

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
...

回答1:


replaceregexp does not have options to skip lines.




回答2:


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

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

2) Read all other properties and save them somewhere.

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

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

5) Enjoy :-)

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



来源:https://stackoverflow.com/questions/7683397/how-to-replace-a-backslash-in-some-lines-of-a-text-in-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!