Count number of regex matches in a Attachment Collection

Hi Everyone,

I need help to count number of regex matches in attachment collection based on filename. I do have the pattern which is .(?i)^(\d{12})_(A|B|C)(.)$ but I don’t know how to check every attachment names if it followed this pattern using Linq maybe and not using for each.

Thank you in advance.

Hi @ppr sorry for tagging again. Do you have idea for this. Thank you :smiley:

Hi @mnlatam

Try this

Let’s say attachment collection is attachments

Now see the below code

attachments.AsEnumerable().Where(Function (e) System.Text.RegularExpressions.Regex.Matches(e.Name.ToString,regexpattern).Count<>0).Count

This will give the count of FileName matching regex pattern


Nived N :robot:

Happy Automation

1 Like

Hey @mnlatam

Try using write line to review the results:

Then use an IF condition accordingly.


Check here for more info:

1 Like


This code works for me. :smiley:
One more thing I might also need to get the matching file names. How will I be able to select the matching names only and I want it to store it in a list? Thanks!

Hi @mnlatam
Just modify the above code itself

file_list=attachments.AsEnumerable().Where(Function (e) System.Text.RegularExpressions.Regex.Matches(e.Name.ToString,regexpattern).Count<>0).ToArray()

here file_list is String

Nived N

1 Like


Did this work around ?

If yes kindly mark the appropriate answer as solution


Nived N :robot:

Happy Automation

Yes I did get it and works perfect. Many thanks guys!! :grinning:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.