Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant 如何用文件的第一部分替换文件?_Ant - Fatal编程技术网

Ant 如何用文件的第一部分替换文件?

Ant 如何用文件的第一部分替换文件?,ant,Ant,给定包含以下内容的文件prep.js: head middle tail 以及build.xml文件: <?xml version="1.0" encoding="UTF-8"?> <project name="abc" default="build"> <target name="build"> <replaceregexp file="./prep.js" match="(.*)(middle)(.

给定包含以下内容的文件prep.js:

head
middle
tail
以及build.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project name="abc" default="build">
  <target name="build">
    <replaceregexp file="./prep.js"
                   match="(.*)(middle)(.*)"
                   replace="\1"/>
  </target>
</project>
但我希望:

head
如何获得我期望的内容?

提到了一个将文件内容视为单行的标志。您也可能不需要匹配中间的单词,因为模式应该只保留第一行,因此您可以尝试:

<replaceregexp file="./prep.js"
               match="([^\r\n]*)(.*)"
               replace="\1" flags="s" />

[^\r\n]
匹配除换行符以外的所有字符

<replaceregexp file="./prep.js"
               match="([^\r\n]*)(.*)"
               replace="\1" flags="s" />