SURESH K
SURESH K

Reputation: 1

Using regular expression split lists in ANT

Input String :- [abc,xyz,mnp,aox,3ds,k42] [brf,fd3,asd,45s,tsd]

I want to print both list separately like

list 1 :- abc xyz mnp aox 3ds k42

list 2 :- brf fd3 asd 45s tsd

Currently i am able to print only first list with the below code.

<propertyregex property="lists" input="${inputString}" regexp="\[(.*)\]" select="\1" casesensitive="false" global="true" />
<echo>list 1 :-</echo>
<for list="${lists}" param="gv">
   <sequential><echo>@{gv}</echo></sequential>
</for>

Please help me how can i resolve this issue.

Regards, Suresh

Upvotes: 0

Views: 273

Answers (1)

Rebse
Rebse

Reputation: 10377

No need for additional libraries like antcontrib, use the builtin javascript engine (Java >= 1.6.0_06)
with ant script task like that :

<project>

 <property name="foobar" value="[abc,xyz,mnp,aox,3ds,k42] [brf,fd3,asd,45s,tsd]"/>

 <script language="javascript">
 <![CDATA[
   var lists = project.getProperty('foobar').split(' ');
   for (var i = 0; i < lists.length; i++) {
     var list = lists[i].replace('[', '').replace(']', '');
     var items = list.split(',').join().replace(/,/g, ' ') ;
     print('list ' + i + ': ' + items);
   }
 ]]>
 </script>

</project>

output :

[script] list 0: abc xyz mnp aox 3ds k42
[script] list 1: brf fd3 asd 45s tsd

Upvotes: 1

Related Questions