【问题标题】:ANT + propertyregex problemANT + propertyregex 问题
【发布时间】:2011-06-27 11:34:17
【问题描述】:

我的条件中有以下字符串:10.13.0.90:7000

我想把它提取成两个条件,例如10.13.0.90和7000。

我试过了 <propertyregex property="client.ip" input="${client.address}" regexp="[0-9.]*:[0-9]*" select="\1" /> 但这不起作用。条件肯定是正确的。有什么建议吗?

非常感谢!

【问题讨论】:

    标签: java regex ant


    【解决方案1】:

    \1 表示第一个分组。但你根本没有分组()

    试试这个:

    <propertyregex property="client.ip" input="${client.address}" 
    regexp="([0-9\.]*):[0-9]*" select="\1" />
    

    【讨论】:

      【解决方案2】:

      您需要使用括号来捕获您使用“\1”引用的组,例如

      regexp="([0-9.]*):[0-9]*"
      

      顺便说一句,您可以使用\d 而不是[0-9] 来表达数字,例如

      regexp="(\d.*):\d*"
      

      【讨论】:

        猜你喜欢
        • 2011-09-24
        • 2013-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多