Please help regex expresion to filter 4 numbers in filename

Hello Friends,
I need your help to find a regular expression being able to filter an attachement whose name is composed by 4 numbers (begining by 4 numbers) and the extension are .xls ,csv or .xlsx

if file name is composed by letters or less than 4 numbers , the regular expression should be able to filter that.

Thanks in advance
Ricchch

Hi @Ricchch

Try this

\b\d{4}\.(xlsx|xls|csv)\b

image

Cheers!!

1 Like

Hi @Ricchch

- BoolFlag = System.Text.Regularexpressions.regex.Ismatch(Input,"^\d{4}(?=.xls|.csv|.xlsx)")

Check the below image for better understanding,
image

BoolFlag is the boolean variable. It will give you true if the filename is with 4 numbers and following with extensions. It will give false if the file name is less than or greater than 4 numbers and letters.

Check the below workflow, If the input is 1134.xlsx -

Check the below worflow, If the input is abcd.xls

Hope it helps!!

1 Like

@Ricchch

I believe this is what you need

\d{4}.*\.(xlsx?|csv)

Cheers

1 Like

@lrtetala @Anil_G @mkankatala @indra
Thanks to all of you…!

It Works

2 Likes

Hello Friends,
i need an extra help please.
the regex works when there is just one attachment in the email.

However , when i have more that one attachment in the email , it is not able to filter attachment respecting the rules comparing to those not respecting rules .

in other words, it can’t filter filesnames with letters and having less of 4 number when email has more than one attachment and one of them is correct and the other ones not…

Thanks for helping

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