Extract 'From' and email body limit

Hi team, I wanted assistance:
I have a regex that extracts the outlook subject here:

but I get the error out of bound
image
This is the subject line I was trying to extract:
image

I want to extract everything from the subjectline.

I Also wanted to ask is there a way to increase the size of the string that UiPath can take:
I was trying to extract an email body here

Hey @Anelisa_Bolosha1,

Your Regex is likely failing with an “Index outside the bounds of the array” error because the Split operation didn’t find the expected pattern. This results in an array with fewer elements than you’re trying to access. The best solution is to use a more robust Matches activity to find all instances of your pattern, or at a minimum, check the array’s size before attempting to access a specific index.

Official UiPath documentation on using Regex activities can be found here:

Let me know if you need anything else

@Anelisa_Bolosha1

the error states that your subject: split failed

how long is your string? generally it can accomodate upto mbs of data so should be fine

cheers

Hi @Anil_G ,
This would be the subjectline I am trying to extract:

Subject: 00091615001001 Mr STEVENS, R Pl 1784778, Cl Cl00436720

image

Dear @Anelisa_Bolosha1,

Since you are extracting outlook email subject, why dont you make use of outlook activities? Any restrctions?

It will be much easier to extract Subject,From & body with acitvities.

Br,
NikZ

Hi @Nikhil_Zambare1 ,
I am using regex since these emails are trails, so I am only working with the first email that came in for example an email would come like this:

So here I would be working with email 2 on the bottom and extract ‘From’, ‘To’, ‘Subject’
So that is the subject I was trying to extract on email 2

This is the pattern i’m using not sure why it is failing

Dear @Anelisa_Bolosha1,

To retirve Subject of 2nd email as highlighted by you.
Use below expressions’

  1. For Subject: EmailBody.Split(“Subject:”,StringSplitOptions.None).Last.Trim.Split(Environment.NewLine)(0).Trim

  2. For From:
    EmailBody.Split(“From:”,StringSplitOptions.None).Last.Trim.Split(Environment.NewLine)(0).Trim

  3. For To:
    EmailBody.Split(“To:”,StringSplitOptions.None).Last.Trim.Split(Environment.NewLine)(0).Trim

If it resolved your issue, kindly mark as solution :slight_smile:

Br,
NikZ

Hello @Nikhil_Zambare1 , thank you for your response back, I checked it


But receiving the below error, my variables are strings

Dear @Anelisa_Bolosha1 ,

Use the expression exactly I did expect EmailBody varaible & try.

Br,
NikZ

Hi @Nikhil_Zambare1 , The variable ‘Emailbody’ that I have it gives me the whole email trail , the variable I am using to extract the subject is EmailbodyTrail - so this would be the first email which has the subject,from,To,body

When I use the emailbody variable that extracts the whole email trail I get the below, with exactly the pattern given:

This is when I use the variable ‘Emailtrail’ which extracts exactly the first email from the trail I get:

Hi, I even tried this pattern:

System.Text.RegularExpressions.Regex.Match(EmailBodyTrail,“(?<=Subject:).*”,System.Text.RegularExpressions.RegexOptions.MultiLine).Value

The results come out empty.
This is the subject I want to extract:
image

Subject: 00091615001001 Mr STEVENS, R Pl 1784778, Cl Cl00436720

@Anelisa_Bolosha1

can you try tow rite it to a file and check how it looks

may be there are some special characters

or add breakpoint and check the variable in locals panel

cheers

In the local panel it’s null

image

@Anelisa_Bolosha1

you need to check the emailbodytrail

cheers

The emailTrail has a value, when I checked. I had to write it in a text file and it turns out it does not extract the whole email.
From the text file here are the results:

The email starts from here, this is the whole email but it just extracted the footer of the email:

This would be the activity I used to extract email trail:

@Anelisa_Bolosha1

that extraction of FROM keyword is failing..thats the reason youa re getting wrong string

cheers

I came right here, I just had to put :

infront of (From:) on my EmailbodyTrail variable

1 Like