How to get data from between two string using REGEX?

This is my mail body which i am extracting and its totally dynamic…
first scenario:
image
second scenario:
image
Sometime i received mail like first scenario as well as second scenario
I want regex code to extract this selected blue part from mail

Hi @Vinit_Mhatre,

Would you be so kind as to share the actual text with us?

Kind Regards,
Ashwin A.K

Hi @Vinit_Mhatre ,

In the Second Scenario, we do not have a Boundary like "Regards",

Hence, If the xyz is similar to Data without having any proper format and it is a Free text, It would be difficult to limit the capture.

But if we do have a New Line Separated between Data and xyz or Regards, We should be able to use it at our advantage.

Nvm i figured it out, can you tell me how to remove this extra space from string
image
image

actually i used this expression its working properly

System.Text.RegularExpressions.Regex.Match(strInput, "(?<=today.)[\S\s]*(?=Regards)|(?<=today.)[\S\s]*(?=Vinit Mhatre)").Value

Hi @Vinit_Mhatre ,

Could could give this a try and see if it works →

System.Text.RegularExpressions.Regex.Replace(str_variable,"\s{2,}","")

Kind Regards,
Ashwin A.K

Thanks got the final ouput like i want it :slight_smile:

1 Like

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