Identify usernames in email body

Dear all

I have to identify a 8 character long usernames in a email body.
My idea is to parse the complete text (from an email body) and find all words that is 8 characters long and look them up in the user database.

My question: How to identify all words in a text which is 8 char long?

Remark: a username can be both letters and numbers eg: A1234567, Test1234, abcdefg1 or 1234567A etc.

Thanks!

@robert.justesen, The best way is to use Regex

In Matches Activity,

Input - Your Email body which is a string
pattern - ([A-Z0-9a-z]{8})
Output - Save to a variable of type (Ienumerbale(of match))

Regardfs,
Dominic :slight_smile:

2 Likes

Hi @robert.justesen,

@Dominic if you use regex sometime return false if mail length is small

For Example Mail id is strMail = a1c2v3@gmail.com
IntMailIdLength=strMail.Split("@"c)(0).ToString.Length

if condition IntMailIdLength<=8
Then
strUserName=strMail.Split("@“c)(0).ToString
else
strUserName=strMail.Split(”@"c)(0).Substring(0,7)

Regards,
Arivu

@arivu96, As robert requirement is to match from Mail Body not from Mail Id

@robert.justesen, Correct me if I am wrong .

Regards,
Dominic :slight_smile:

1 Like

Thanks for your reply’s

Yes - it is from the mail body and the username is not an e-mail

The Mail.Body could look something like this:

Dear Mr. Justesen
My old username for the Microsoft system is X1234567 and …
BR Justesen

The accepted result is:
Justesen
username
X1234567
Justesen

With the ([A-Z0-9a-z]{8}) I’m also getting Microsof as a result.

Resolved it with a \b before and after:

Regex.Matches(Mail.Body,“\b([A-Z0-9a-z]{8})\b”)

Thanks !!

3 Likes