How can I extract the last row from the given data using Reg EX

Hi All,

I want to extract the last row and second last row (separate) from below string using Reg-Ex

Delivery - Additional Information Requested - 2022-08-29 15:46:51 - a.als.a
Delivery - Open - 2022-09-05 09:45:54 - ll.als.a
Delivery - Work in Progress - 2022-09-06 10:11:17 - ooak
Delivery - Reviewed - 2022-09-12 08:13:51 - kkkais
Delivery - Additional Information Requested - 2022-09-18 12:15:06 - kan.skd
Delivery - Open - 2022-09-28 10:22:59 - kaj.sji
Delivery - Work in Progress - 2022-09-28 11:58:45 - abc.jsh

Thanks,
Rushi

HI @Athawale_Rushikesh

System.Text.RegularExpressions.Regex.Matches(YourString,"(?<=Delivery\s-\s)\S.+")(1)

Output -> Open - 2022-09-05 09:45:54 - ll.als.a
System.Text.RegularExpressions.Regex.Matches(YourString,"(?<=Delivery\s-\s)\S.+")(6)

Output -> Work in Progress - 2022-09-28 11:58:45 - abc.jsh

Regards
Gokul

Hi,

How about the following?

The last row

System.Text.RegularExpressions.Regex.Match(yourString.Trim,".*$").Value

the second last row

System.Text.RegularExpressions.Regex.Match(yourString.Trim,".*(?=\n.*$)").Value

This works in any number of rows.

Regards,

@Athawale_Rushikesh ,

With a Regex Split or even with a Normal Split, we could get Split the text based on new line and get the data using Indices :
image
For Last Line Data :

Regex.Split(wordText,"\n")(Regex.Split(wordText,"\n").count-1)

For Last but one line Data :

Regex.Split(wordText,"\n")(Regex.Split(wordText,"\n").count-2)

Hi @Athawale_Rushikesh find this workflows

Testing2.zip (1.8 KB)

Thanks all, everyone has given the solution for expected output.

I have implemented the @Yoichi’s solution.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.