How do I check to see if the regex has the @ sign in the output


My bot is scraping a PDF, using regex it is looking for anything between “(?<=ToEmail:).*(?=::CcEmail)” the result is ToEmail

So what I want to do is for each pdf read the PDF if condition (???) unclear as to how to write the if condition so that if it exists move the PDF to this file else move the pdf to this file.

Hey @jeff.shubzda

I guess you want to verify if the text is an email.

You can just use email regex available over internet to match and use.

Hope that helps

Thanks
#nK

Well sort of I read the PDF and in some of the PDFs there is an email address so I use regex to find that email, if it’s not there move to the else but I’m not sure how to write the condition?

Hey @jeff.shubzda

Use matches activity above IF and check in if if the output variable has some match.

Below is the regex to use in matches activity.

[1]+@([\w-]+.)+[\w-]{2,4}$

Condition as below

MatchesOutputVariable.Count>0

Kindly try this.

Thanks
#nK


  1. \w-. ↩︎

I tried the above solution but it didn’t not give me the results I was looking for. In this screen you can see that I am getting the email address out of the PDF, what I need to do is use an if condition because I sometimes does not get anything out of the PDF example

Display Email Address Elizabeth.Adams@youradd.org (if an email is present)
Display Email Address (if not)

Out of the matches I get this - ToEmail which I ready and display in using “Display Email Address” + ToEmail(0).Value

In my if condition I have this code - EmailString.ToUpper.Trim .Contains (“@”) which I know is probably wrong This is where I need the help writing the if condition based on what I am getting? thanks

Hi @jeff.shubzda

Have you tried the IsMathch Activity?

Is Match (uipath.com)

I did not let me try that now…thanks

Display Email Address Elizabeth.Adams@you.org (“Display Email Address” + ToEmail(0).Value)
Display Email Address) is a valid email (“Display Email Address” + String.Format(“{0}) is a valid email”, EmailToCheck)

These are what I log the bot doesn’t seem to use the if condition right it never gets to the then statement

I follow the example and I used the is matches the extractedPDF goes in and the results (IsMatch)

Hey!

Try like this…

System.Text.RegularExpressions.regex.Match(strInput,"(?<=ToEmail:).*(?=::CcEmail)").ToString.Trim.Contains("@")

Use this in if condition…

There is no point of using the Matches activity I guess

Regards,
NaNi


that if seems right but it never gets to the then area??? Yet this is what is displayed - Display Email Address Elizabeth.Azzzzams@you.org

Hey!

Cool…

The mail id which you mentioned is it getting from the regex?

if yes we can directly use that variable…

strInput.Contains("@")

It could be better if you can show us the variable where we’re getting the mail ID from?

Regards,
NaNi

This is the regex I use to get the results “(?<=ToEmail:).*(?=::CcEmail)” results is ToEmail in the assign i have strInput = ToEmail(0).Value

Got it…

Use the below expression in If Condition

StrInput.Contains("@")

Try this and let me know

This will fetch the data if the text contains @ or Not…

Regards,
NaNi

Looked like it worked then I get this
image
Assign: Object reference not set to an instance of an object.

Hey!

Remove the Matches activity and take one assign activity you can pass the regex like this…

Assign strInput = System.Text.RegularExpressions.regex.Match(strInput,"(?<=ToEmail:).*(?=::CcEmail)").ToString.Trim

This will give you the mail ID

Regards,
NaNi

I probably missed one part sometime this is the string that comes back Patient Satisfaction Scores
Abidi, bbbbb Y MD
ExportName: ::EmailSubject: ::ToEmail: ::CcEmail: ::FromEmail: :: Rate this Provider
Fiscal YTD
This is the data in the PDF someties is does not have an email address so I think that is why I get this error? Assign: Value cannot be null.
Parameter name: input

Hey!

It could be better to show us the inputstring

Regards,
NaNi

The output string is above - ExportName: ::EmailSubject: ::ToEmail: ::CcEmail: ::FromEmail: :: Rate this Provider or if an email is there it looks like this
ExportName: ::EmailSubject: ::ToEmail: Frank@me.org CcEmail: ::FromEmail: :: Rate this Provider

Hey!

Use IsMatches activity and do the following modifications…

RegExEmail

Provide the input as - PdfOutputVariable
Output as EmailFound - Boolean Type

Now take one if condition

Provide the EmailFound=True

In then Block you’ll get the Email ID’s
In else block you Won’t get anything and do all the steps in Then block

This will work for sure

Regards,
NaNi

1 Like

Thank you, thank you, thank you!!! Your have saved my liver :slight_smile:

1 Like