regx在多行字符串来选择最后一行 [英] regx to select last line in a multi-line string

查看:184
本文介绍了regx在多行字符串来选择最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ANT脚本这将有其值的属性可以是例如一个或多个线
财产

I have an ANT script which will have a property whose value could be one or more lines e.g. property

prop1=
A_12.1_REL_B121000_10_18_2011.1700
A_12.1_REL_B121001_10_25_2011.6059
A_12.1_REL_B121001_10_25_2011.2201
A_12.1_REL_B121001_10_25_2011.2014

请参阅所有这些线路用CRLF和文件结束而终止也是另一个CRLF。现在我需要做的只是选择使用正则表达式的最后一行。线的数量可以是更少或更多的例如

Please see that all these lines end with a CRLF and end of file is also another CRLF. Now what I need to do is just select the last line using a regex. The number of lines could be less or more e.g

prop1=
    A_12.1_REL_B121000_10_18_2011.1700  

在第二种情况下,我需要选择这一行。
我寻觅旧帖子,但没有找到任何具体的。任何指针?

In the second case I need to select this single line . I have searched older posts, but could not find anything specific. Any pointers ?

推荐答案

如果您使用的是蚂蚁的contrib

    <loadfile srcFile="input.prop" property="test"/>

    <propertyregex property="result"
                   input="${test}"
                   regexp="(.*$)"
                   select="\1"
    />

    <echo message="Result is : ${result}"/>

这将始终打印输入属性的最后一行文件:

This will always print the last line of your input properties file :

[echo] Result is : A_12.1_REL_B121001_10_25_2011.2014

这篇关于regx在多行字符串来选择最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆