我需要一个正则表达式来提取JAR名称和版本。输入值是在下面的格式:路径目录的正则表达式
C:\WORK\Modify file\test2\lib\messageclass-12.jar
C:\WORK\Modify file\test2\lib\utilities-396.jar
C:\WORK\Modify file\test2679\lib\castor-1.jar
输出应为:
messageclass
12
utilities
396
castor
1
任何帮助理解。 更新
我在蚂蚁脚本中使用这2个属性的值来提取:MessageClass的和12波纹管:
<propertyregex override="yes" property="propA" input="@{file}" regexp="here should be the regex" replace="" global="true" />
和@ {文件}是INFACT C:\ WORK \修改文件\ TEST2 \ LIB \ MessageClass的-12.jar
样本例子上可以找到:http://ant-contrib.sourceforge.net/tasks/tasks/for.html
根据您的建议最终的解决方案是:
<!-- calculate jar name -->
<propertyregex override="yes" property="jarname" input="@{file}" regexp="-(\d*)\.jar" replace="" global="true"/>
<propertyregex override="yes" property="jarname" input="${jarname}" regexp=".*\\(\S*)\\" replace="" global="true"/>
<!-- calculate jar version -->
<propertyregex override="yes" property="jarversion" input="@{file}" regexp=".*\\(\S*)-" replace="" global="true"/>
<propertyregex override="yes" property="jarversion" input="${jarversion}" regexp=".jar" replace="" global="true"/>
你在用什么语言?使用某种'Path.Split'类型的函数来获取文件名可能会更好,然后使用字符串函数在'-'上进行分割(或者如果真的需要使用正则表达式) – Blorgbeard 2011-04-01 08:12:44
我更新了问题,谢谢你的回应。 – 2011-04-01 08:25:10