How to extract OTP

Hi i have the above outlook mail i need to extract Verification Code number. Can anyone please help me in extracting only that Number.

Thanks in advanceotp

Assuming the verification code length is 5.

string strOutlookBodyText = “Body of the Email”

int Index = strOutlookBodyText.IndexOf("Verification Code:")
int iVerificationCode = strOutlookBodyText.SubString(Index + "Verification Code:".Length + 1, 5) 

Regards,
Karthik Byggari

2 Likes

@SIVASHANKAR

Use Matches activity with pattern as (?<=Verification Code:[ ]+)\d+
Just to make sure, once result is retrieved, use trim to remove the whitespace if there any.
This will also work fine even if the verification code length changes.

Hope this is helpful!

1 Like

Can someone pls help me bot takes the previous verification code instead of latest code.

Hey @KarthikByggari

What changes we need to do if the body looks like this?

image

My verification code string says “re.ad” by using the method above and the code’s length is 6 and it might change in future as well. So just wanted to know code structure for that as well if possible.

Thanks in advance :slight_smile:

You can use the following regex pattern to get the verification code -

Regex pattern: [0-9]{6,6}

[0-9] - Digit only
{6,6} - Min & Max - only allows 6 digit number.

If you want to allow 5 digit number, the pattern will be [0-9]{5,5}

Regards,
Kartheek