Help: identifying an attachment composed just 4 numbers

Hello Friends,
i would really appreciated if you could help me with this problem.

I need to verify if an outlook email has an attachment and then check if the attachment name is composed by 4 number
Ex 1234.xlsx or 8945.xlsx

i using this regex but i doesn’t work

mail.Attachments.Any(Function(x)x.Name.ToLower.Contains(“123456789”))

could you please help me with that?

thanks in advance…
Richch

Hey @Ricchch
Try to use for each to loop through the email attachments and then use if activity:
System.Text.RegularExpressions.Regex.IsMatch(CurrentItem.Name, "^\d{4}\.xlsx$")

1 Like

Hi @Ricchch

Can you try this in If Condition when you use For Each loop to iterate through mailMessages variable:

mail.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, "\b\d{4}\.xlsx\b"))

Regards

1 Like

Hi @Ricchch

Can you try the below

isAttachmentValid = mail.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, "\d{4}\.xlsx", RegexOptions.IgnoreCase))

Cheers!!

1 Like

Hello @pikorpa @vrdabberu @lrtetala
Thanks for helping.
I couldn’t yet test your advises (some last minute changing priorities)
i will do it next week and i will get back to you.
In the meantime have a good weekend and thanks again.
Ricchch

2 Likes

Hello @pikorpa ,
thanks for messaging
i tried to capture this excel file :handshake:
image
image
image

Using this phrase in If condition

image
But didn’t work…

do i have to correct something? thanks for helping

@Ricchch

Can you try the below

currentItem.Attachments.Any(Function(attachment) System.Text.RegularExpressions.Regex.IsMatch(attachment.Name, "\b\d{4}\.(xlsx|xls|csv)\b", RegexOptions.IgnoreCase))

Cheers!!

1 Like

Hello friends @vrdabberu , @lrtetala @pikorpa

Thanks for helping to all of you.
Statement in the if conditions

I followed your recommendation with the following

(mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(“.xlsx” )) Or mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(“.xls” )) Or mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(“.csv” )))

AND

(mail.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, “\b\d{4}\b”)))

with this phrase i am able to filter attachments having extension .xlsx, .xls and .csv

then with the next expression i was able to check if the name of the attachment has 4 characteres .

I would really appreciated if you could help me with this extra requirement:

i need this las phrase to be able to filter the name of the attachment but only one having numbers in the attachement name.
Rightnow, the “\b\d{4}\b” seems to filter just those names that has 4 characteres . in other words. if the attachement name is abcd.xls it will got into the IF then . Same for a attachement name 1234.xls

however , i need the phrase condition to send abcd.xls to the Else part of the conditionnal…

Thanks again for any advice or help,

Ricchch

Hi @Ricchch

Can you try the below syntax in If:

mail.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, "^\d+$"))

Regards

thanks @vrdabberu
but didn’t work
Ricchch

@Ricchch

Can you send the screenshots of the workflow what is your exact condition you want t check.

Regards

Hello @vrdabberu
thanks for helping.
in the image below you will find an email with 5 excel attachments.
there are three attachments that complies with requirements ( their names are composed by 4 numbers ) .
Besides that, there are two attachments not complying with requirements( their names have less than 4 numbers or their names are composed by letters)

Therefore , i need the program to be able to filter those having 4 numbers in their names and eliminate those having letters or les than 4 numbers)

My actual phrase in If conditions is:

Thanks

@Ricchch

Are you sure that the excel that you get will contain 4 numbers?

Regards

@vrdabberu

yes… its a requirement.
Thanks

Hi @Ricchch

Can you try the below syntax:

Try the below syntax:

(mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(".xlsx")) OrElse
 mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(".xls")) OrElse
 mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(".csv"))) AndAlso
mail.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, "^\d{4}\.(xlsx|csv|xls)$"))

Regards

@vrdabberu
i tried but it processed all the files (included those ones with three numbers and letters that are supossed not being processed)
Thanks

Hi @Ricchch

Try the below syntax:

mail.Attachments.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch(x.Name, "^\d{4}\.(xlsx|csv|xls)$"))

Regards

its exactly the same i tried.
Thanks

1 Like

@Ricchch

I think your query will be resolved now. If yes, please mark my post as solution to close the loop otherwise if you have questions, I’m happy to help

Regards

@vrdabberu
no , my query was not resolved it has the same problem.
But thanks anyway for trying to help.