Regex to select the last line in a multiline line

I have an ANT script that will have a property whose value can be one or more lines, for example. 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 CRLF, and the end of the file is another CRLF. Now I just need to select the last line using a regular expression. The number of rows may be less or more, for example

 prop1= A_12.1_REL_B121000_10_18_2011.1700 

In the second case, I need to select this single line. I was looking for old posts but couldn't find anything specific. Any pointers?

+4
source share
2 answers

If you are using ant-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 
+1
source

That should do it ...

 /^.*\z/m 

Look in action .

(Suppose m is multi-line mode.)

+5
source

Source: https://habr.com/ru/post/1381848/


All Articles