1

I want to read a text file which has text as follows(sample)
abc ip-32-56-198-18.com xyz
now the text 32-56-198-18 updates dynamically and now i want to take this text and create ip address for further use.

I have done this using PHP but with ant i am in problem as I cant get the position of specific sub-string like php in ant.

I have seen this question its similar but he knows the position of the sub-string my position is too not fix as abc can be string of any length. Only ip- and .com are fix which are sufficient to find the required.

If you all say that its not possible using ant then i can focus or do something else or try different method to fix my problem dropping the plan of reading the same from ANT.

Thanks to all.

Update: abc ip-23-56-89-45.com-asdhba.sip-65-59-85-12.com xyz

for the above example the code should work and it should give me 23-56-89-45 Thanks.

Community
  • 1
  • 1
lAH2iV
  • 1,159
  • 2
  • 12
  • 28

1 Answers1

4

As said in the most rated answer to the question you mentioned, you could try using PropertyRegex from Ant-conrtib.

<project>

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="./ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>

<!-- You can load the value from file -->
<property name="input" value="abc ip-32-56-198-18.com xyz"/>

<propertyregex property="ip"
              input="${input}"
              regexp=".*?ip-(.*?)\.com.*"
              select="\1"
              defaultValue="${path}" />

<echo message="IP addr: ${ip}"/>
</project>
aleung
  • 9,848
  • 3
  • 55
  • 69
  • :your code works but in my text .com comes again and your code is not stopping at first occurance of `.com` it goes further and stops at last occurance of `.com` Please help.... – lAH2iV Aug 08 '11 at 10:04
  • please don't say use twice the same code! This should be last option. – lAH2iV Aug 08 '11 at 10:43
  • For the Updated problem i used `regexp=".*ip-(.*)\.com(.*)\.com"` This is as we select `\1` that means we are using the first one and if i do `\2` it gives the second text. Thanks once again.. – lAH2iV Aug 08 '11 at 10:57
  • @IAH2iV I've updated the regexp in the sample to ungreedy match. Now it works with your both inputs. – aleung Aug 09 '11 at 11:02