【问题标题】:Ant PropertyRegex won't support capture group when in propertyAnt PropertyRegex 在属性中不支持捕获组
【发布时间】:2013-04-17 07:57:06
【问题描述】:

我正在尝试创建一个动态支持 var 替换的 ant 构建目标。

<target name="replace_property" depends="init_ant_contrib">
    <propertyregex input="${replace_inboundproperty"
        property="${replace_outboundproperty}"
        regex="${replace_match}"
        replace="${replace_target}"
        global="true"
        override="true" />
</target>

所以我加载了属性文件,我基本上是这样设置变量的:

replace_inboundproperty="/target/path/targetfile"
replace_outboundproperty=blah
replace_match="/target/(.*)/targetfile"
replace_target="\1"

所以当我回应 blah 时,我得到“1”。现在,如果我真的这样做:

<target name="replace_property" depends="init_ant_contrib">
    <propertyregex input="${replace_inboundproperty"
        property="${replace_outboundproperty}"
        regex="${replace_match}"
        replace="\1"
        global="true"
        override="true" />
</target>

然后 echo blah,我会得到“路径”。

谁能告诉我我缺少什么以允许替换使用属性文件/ant -D 中的捕获组?使用 ant-contrib 1.0b3。

谢谢!

【问题讨论】:

    标签: regex ant


    【解决方案1】:

    发现在属性文件中,如果你双重转义它,它会正常工作:

    replace_target=\\1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多