2014-12-01 48 views
1

指定的文件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> 

運行 「蟻族」 離開文件prep.js有:

head 

tail 

但我預計:

head 

我如何獲得我期望的?

回答

1

documentation提到了一個將文件內容視爲單行的標誌。你也可能不需要匹配中間字的模式應該只保留第一行,所以你可以嘗試:除了換行符

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

[^\r\n]比賽中的所有字符。

+1

只需添加flags =「s」解決了它。謝謝! – 2014-12-01 20:59:00