2011-10-05 56 views

回答

0

你可以使用:http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html

虽然我不知道这是否会做你所要求的。当你回应你的财产时,反斜杠是否可见?

在任何情况下使用上述任务,您将必须安装有蚂蚁的contrib和简单的写这样的任务:

<project name="test" default="build"> 
<!--Needed for antcontrib--> 
<taskdef resource="net/sf/antcontrib/antlib.xml"/> 

<target name="build"> 

    <property name="path" value="C\:Program Files\\test1\\test2"/> 
    <echo message="Path with slashes : ${path}"/> 
    <propertyregex property="removed.backslash.property" 
       input="${path}" 
       global="true" 
       regexp="\\(\\|:)" 
       replace="\1" 
    /> 
    <echo message="Path with single slashes : ${removed.backslash.property}"/> 
</target> 

</project> 

输出:

build: 
[echo] Path with slashes : C\:Program Files\\test1\\test2 
[echo] Path with single slashes : C:Program Files\test1\test2 

此外,您可以使用任何BSF语言:

http://ant.apache.org/manual/Tasks/script.html

只要你使用jre 1.6及以上版本。

+0

当回声,反斜杠是可见的,我也试过你的解决方案。看来你的正则表达式有一些问题? – performanceuser

+0

请尝试更新的答案。它应该开箱即用:) – FailedDev

+0

几乎在那里,我想要将“\:”转换为“:”。看到我的组织职位。 – performanceuser