Last line of letter using REGEX

I am trying to retrieve the last sentence of a letter (remittent name) using Regex. I tested the regex expression online but it does not work in UiPath (^.*\z). Can you please help me with a regex expression to retrieve last line of my letter using an alternative solution? thank you.

@m.soto

can you share a sample text so that ican help

Sure, this is one of the sample letters and need to retrieve the name of the remittent (Kathy Brennan)

"To whom it my concern,
*This letter is intended to serve as my official resignation as an officer *
*in the U.S. Army reserves, my End of Active Services (EAS) is 2/20/23. As *
*per the commission I signed, I have completed all of my requirements *
*and have served the prerequisite amount of time. At this point, I would *
*like to move on from military service and apply what I have learned to a *
civilian career.

  • Thank you for this opportunity and thank you for your cooperation in this *
    *matter. *
    Kathy Brennan"

@m.soto

try this once

outputsr=outputstr.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Last

or

you can use regex

System.Text.RegularExpressions.Regex.Match(outputstr,“[a-zA-Z\s]+$”).tostring.Trim

1 Like

Hi @m.soto ,

Using regex with groups, we should be able to pick the last line value :

(?s:.*\r?\n)*(.+)$

System.Text.RegularExpressions.Regex.Match(InputText,"(?s:.*\r?\n)*(.+)$",System.Text.RegularExpressions.RegexOptions.Multiline).Groups(1).value.ToString

Debug Panel :
image

1 Like

Thanks for your feedback, it worked !

1 Like

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