开发者

Read a dynamic substring from text file using ant

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 positio开发者_如何学编程n 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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜