Ant 替换不以以下字符开头的文件文本
我想制作一个 ant 目标,它可以替换不以定义模式开头的文件(或更多)的内容。有没有使用 ant 和 Replaceregexp 的解决方案?或者有替代方案吗? 示例:
- 我有文件 boo.txt,其中包含以下文本: “这是嘘”。
- 我还有文件 foo.txt,其中包含以下文本: “只是富”。
我想将 foo.txt 的文本更改为: “这只是 foo”
I want to make an ant target that can replace the content of a file (or more) that does not starts with a defined pattern. Is there a solution for this using ant and replaceregexp ? Or an alternative to this?
Example:
- I have file boo.txt that has the text:
"this is boo". - Also I have the file foo.txt that has the text:
"just foo".
I want to change the text for the foo.txt to:
"this just foo"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是用捕获编写合适的正则表达式的情况。
这似乎适用于您给出的示例。
files
目录中的所有文件。this
,它存储在属性中,因为我们需要在两个地方提及它。flags="s"
设置确保我们将文件视为单个字符串以进行匹配(而不是匹配每一行)。\1
中 - 它将被丢弃。\2
中。\2
。您可能会认为它总是添加前缀,但是如果前缀已经存在,则将其删除...除了
replaceregexp
任务将不会写入文件,除非与现有文件不同。Probably a case of cooking up a suitable regular expression with captures.
This one appears to work for the example you give.
files
directory.this
, which is stored in a property, as we need to mention it in two places.flags="s"
setting ensures that we treat the file as a single string for match purposes (rather than matching each line).\1
- which is discarded.\2
.\2
.You might think of it as always adding the prefix, but after taking the prefix away if it's already there...except that the
replaceregexp
task will not write the file unless if differs from the existing.这只是部分答案..我不确定它是否正确,但至少也许可以给你一些方向
,你需要 ant-contrib
this is just a partial answer.. I'm not sure if its correct but at least maybe can give you some direction
for this you need ant-contrib