Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex pattern to valid file name

Tags:

c#

regex

I have a list of filenames which will have name like this :

ADB_FULL_REQ_XXXXXXXXXXXX_151004_01.dat 

Where :

ADB_FULL_REQ_ is constant

XXXXXXXXXXXX is the computer's Mac Address

151004 represents the date in yyMMdd format

01 is 2 digits and maximum is 99

I will have to perform a search in the diretory which contains those files and check if any of them is invalid/valid.

I've tried to use RegEX with this pattern but Match.Success always return false :

Match match = Regex.Match(filename, @"^ADB_FULL_REQ_XXXXXXXXXXXX_(d\{6})_(d\{2}).dat")

Please show me what'm I doing wrong here? Thanks!

like image 239
EagerToLearn Avatar asked Jul 02 '26 20:07

EagerToLearn


1 Answers

The mistake is not big:

^ADB_FULL_REQ_[a-fA-F0-9]{12}_(\d{6})_(\d{2}).dat

you used d\ instead of \d. Change it and this will work fine (I've added checking for MAC address).

like image 71
Kamil Budziewski Avatar answered Jul 05 '26 10:07

Kamil Budziewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!