Thinking
Thinking

Reputation: 211

Is it possible to write a regular expression for finding a typical file matching pattern in config file(C#)

Is it possible to write a regular expression for finding a typical file matching pattern.

e.g. File<13/04/2010>.txt should be picked up and not any other file.

i.e. Starting file name will be File followed by some dates and then the file extension.

If so, can we specify this pattern in the config file?

Looking for the solution in C#

Thanks

Upvotes: 1

Views: 103

Answers (1)

tanascius
tanascius

Reputation: 53944

You can match

@"File\d{2}/\d{2}/\d{4}\.txt"

This matches File at first, then exactly two digits \d{2} followed by / ...
After the date, it matches a dot \. and the file-extension.

To match only files from april 2010 you can use something like @"File\d{2}/04/2010\.txt"

Upvotes: 1

Related Questions