Reputation: 207
Question for any RegEx masters out there who have a minute to help me out... I have an application which allows users to specify a filename which is used to grab files off of an ftp or local directory... In the filename, they are allowed to specify wildcards using the * character...
Examples include:
file1*.txt, *.* , acb*.* , file.txt , *abc*.xml , filewithnoext*
I need a dynamic regular expression to filter my file list and only retrieve files based on the users input... Can anyone out there help me with this? Thanks for taking the time to take a look.
Upvotes: 0
Views: 147
Reputation: 2482
You could try something like this:
string reg = Regex.Escape(userinput).Replace(@"\*", ".*?");
Then iterate through each file and check them by doing something like this:
foreach (string file in files)
{
if(!Regex.Match(file + "$", reg).Success)
continue;
//...
}
Upvotes: 2