如何在 Ant 中替换文本某些行中的反斜杠
使用
<replaceregexp byline="true" flags="g" file="${someFIle}"
match = "[\\]"
replace = "/"/>
I 可以轻松地将所有 \ 替换为 /。
但
假设文本是:
Other A\B\C
Some C\D\E
Other ...
Other ...
...
如何在具有前缀“Some”的第二行中用“/”替换“\”,而不是其他行:
Other A\B\C
Some C/D/E
...
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
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
replaceregexp
没有跳过行的选项。replaceregexp
does not have options to skip lines.您的问题不能仅通过单个正则表达式来解决。你需要做一些更复杂的事情。
1) 仅读取具有指定前缀的属性并将其保存到变量中。这可以通过 propertyregex 来完成。
2) 读取所有其他属性并将它们保存在某处。
3) 将 \ 替换为包含前缀的属性中您想要的任何内容。
4) 将修改后的属性与不带前缀的属性写入文件中替换原文件。
5) 享受吧:-)
尝试一一执行这些步骤。如果您仍有疑问,请告诉我。
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.