我需要将标准Ivy依赖标签映射到它的三个属性(org、name、rev)中。
以下代码不会捕获任何
<!-- <dependencys+org="([^"]+)"s+name="([^"]+)"s+rev="([^"]+)".*/> -->
<regexp id="ivyPattern" pattern="<dependencys+org="([^"]+)"s+name="([^"]+)"s+rev="([^"]+)".*/>" />
<target name="capture" depends="ivy-config">
<input message="Input dependency" addproperty="dependency" />
<propertyregex casesensitive="false" regexp="ivyPattern" input="${dependency}" select="1" property="org" />
<propertyregex casesensitive="false" regexp="ivyPattern" input="${dependency}" select="2" property="name" />
<propertyregex casesensitive="false" regexp="ivyPattern" input="${dependency}" select="3" property="rev" />
<echo message="Dependency: ${dependency}" />
<echo message="Org: ${org}" />
<echo message="Name: ${name}" />
<echo message="Rev: ${rev}" />
</target>
测试结果:
[echo] Dependency: <dependency org="org.apache.cxf" name="cxf-api" rev="2.7.12"/>
[echo] Org: ${org}
[echo] Name: ${name}
[echo] Rev: ${rev}
BUILD SUCCESSFUL
正如您所看到的,我已经使用在线资源(freeformatter.com)对XML模式进行了转义
为什么它不起作用?每一个regex测试人员都说(unscaped)模式非常有效!
以下修改后的代码有效:
<propertyregex casesensitive="false" input="${dependency}" select="1" property="org" >
<regexp refid="ivyPattern"/>
</propertyregex>
<propertyregex casesensitive="false" input="${dependency}" select="2" property="name">
<regexp refid="ivyPattern"/>
</propertyregex>
<propertyregex casesensitive="false" input="${dependency}" select="3" property="rev">
<regexp refid="ivyPattern"/>
</propertyregex>
声明的正则表达式必须在具有refid
属性的regexp
标记中引用