正则表达式选择多行字符串中的最后一行
我有一个 ANT 脚本,它有一个属性,其值可以是一行或多行,例如 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。现在我需要做的就是使用正则表达式选择最后一行。行数可以更少或更多,例如
prop1=
A_12.1_REL_B121000_10_18_2011.1700
在第二种情况下,我需要选择这一行。 我搜索了较旧的帖子,但找不到任何具体内容。有什么指点吗?
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
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以做到...
查看实际操作。
(假设
m
是多行模式。)This should do it...
See it in action.
(assume the
m
is multi-line mode.)如果您使用 ant-contrib :
这将始终打印输入属性文件的最后一行:
If you are using ant-contrib :
This will always print the last line of your input properties file :