How to scrape specific data from text file

Hi all,
I am a newbie here.
I need to scrape specific data from below mail body which is saved in text file -
Dear valued Customer,
These are the details we received,

First Name : abc
Last Name : xyz
Email :
Feedback for : xyz Services
Feedback : some content

Best regards,

I need to extract Name,Email,Feedback for and Feedback from the text file and paste it in an excel file for about 20 mails.

How do I do that?Please help…
Thanks in advance.


Hell @ys0217 and welcome to the community!!
We can extract those values easily with Regex Matches activity (There is even a tutorial for it on UiPath Academy!).

You can use these patterns to get the desired values:

(?<=First Name :).*

(?<=Last Name :).*

(?<=Email :).*

(?<=Feedback for :).*

(?<=Feedback :).*

Go ahead and try it, and give us a response if you find something hard.


Thanks a lot for ur response. Regex concept is completely new for me. Is there any other way to do it ?

1 Like

@ys0217 Yes you can read text file line by line and split based on : so you can get the result

I tried this but I’m getting array index out of bounds exception when I try to add the result into collection.

@ys0217 Can you share the screenshot of error

1 Like

Invoices.xaml (9.7 KB)

here is an example


Welcome to uipath community
Hope this would help you resolve this
—hope you have the mail message ready in a variable or inside a for each loop activity with list of mailmessage variable from get outlook mail activity
—let’s take we have for each loop activity with the variable obtained from get outlook mail activity as input
—now inside the loop use a assign activity like this
Outmailbody = item.Body.ToString
—another assign activity as
Outbodystring = String.Join(“ “,Outmailbody.Split(Environment.Newline.Toarray(),StringSplitOptions.RemoveEmptyEntries))

—now we will be getting the individual values
With some set of assign activities like this
Out_FirstName = Outmailbody.SubString(Outmailbody.IndexOf(“First Name”)+13, (Outmailbody.IndexOf(“Last Name”) - Outmailbody.IndexOf(“First Name”)+13)).ToString.Trim

Next assign activity
Out_LastName = Outmailbody.SubString(Outmailbody.IndexOf(“Last Name”)+11, (Outmailbody.IndexOf(“Email”) - Outmailbody.IndexOf(“Last Name”)+11)).ToString.Trim

For full name
Outfullname = Out_LastName + “ “ + Out_LastName

Next assign activity
Out_Email = Outmailbody.SubString(Outmailbody.IndexOf(“Email”)+7, (Outmailbody.IndexOf(“Feedback for”) - Outmailbody.IndexOf(“Email”)+7)).ToString.Trim

Next assign activity
Out_Feedbackfor = Outmailbody.SubString(Outmailbody.IndexOf(“Feedback for”)+14, (Outmailbody.IndexOf(“Feedback”) - Outmailbody.IndexOf(“Feedback for ”)+14)).ToString.Trim

And finally assign activity be like
Out_Feedback = Outmailbody.SubString(Outmailbody.IndexOf(“Feedback”)+10, (Outmailbody.IndexOf(“Best regards”) - Outmailbody.IndexOf(“Feedback”)+10)).ToString.Trim

Make sure that all the index position and strings been referred are same
May be we can moderate a bit on index values if any small mismatch occurs

Hope this would help you
Cheers @ys0217


Thanks alot for the detailed reply. Will try this out.

1 Like

I am getting blank outputs for the regex (?<=First Name : ).*

No worries
Cheers @ys0217

what are those numbers 13, 14, 10 etc ? Do i need to modify it?

1 Like

Getting this error:

They are number of characters
Kindly use individual assign activities
Cheers @ys0217

Sure. Thank you :slight_smile:

1 Like

I could extract first name, last name and email from using this method Sir, but Feedback for and Feedback is not extracted properly because of same word in both cases that is “Feedback”.

Kindly help with this issue.
Thanks in advance.

1 Like

To get the feedback for and feedback
Out_Feedbackfor = Out_mailbody.Split(“Feedback for : ”,Stringsplitoptions.Removemptyentries)(1).ToString.Trim.Split(“Feedback”)(0).ToString.Trim

Then for
out_feedback = Out_mailbody.Split(“Feedback : ”,Stringsplitoptions.Removemptyentries)(1).ToString.Trim.Split(“Best regards”)(0).ToString.Trim

Hope this would help you
Kindly try this and let me know for any queries or clarifications
Cheers @ys0217


Hi @srdjan.suc ,

Can you please share the tutorial link of regex available on UI academy.


1 Like

@mukeshkala Is it possible to share your text file so it will be easy to give better solution.