Reputation: 68
I need a regular expression for extracting a JAR name and a version. The input values are in the below format:
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
output should be:
messageclass
12
utilities
396
castor
1
Any help is appreciated. Update
I am using this in a ant script to extract in 2 properties the values: messageclass and 12 as bellow:
<propertyregex override="yes" property="propA" input="@{file}" regexp="here should be the regex" replace="" global="true" />
and @{file} is infact C:\WORK\Modify file\test2\lib\messageclass-12.jar
A sample example can be found on: http://ant-contrib.sourceforge.net/tasks/tasks/for.html
Final solution based on your suggestions is:
<!-- 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"/>
Upvotes: 1
Views: 2113