c# - why Linq Query with Regex statement get locked -


i'm trying filter search using regex object bot on filesytem ftp research. if run snippet on ftp works , if run on local filesystem ,it not respond :

on ftp

string[] filesarray = ftp.listdirectory(@"/" + srcpath + @"/").where(filename => regex.ismatch(filename, /*@"^[a-za-z0-9\-]*?$"*/"(.*)"+ srcmask, regexoptions.ignorecase)).toarray(); 

on local filesystem

 string[] files = directory.getfiles(srcpath).where(filename => regex.ismatch(filename, "(.*)" + *.pdf, regexoptions.ignorecase)).toarray()  

doing same foreach , notice when hits "none pdf" file, on if condition, statement locked:

string input = "*.pdf"; regex regx = new regex("(.*)"+input);  string[] filesname = directory.getfiles("c:\\temp\\").select(filename => new fileinfo(filename).fullname).toarray(); foreach(string s  in filesname) {     if (regx.ismatch(s))     {         file.copy(s, "c:\\temp\\files\\"+s.split('\\').last(), true);         count++;      }     console.writeline(count);               } 

the short answer

(.*)*  

causes backtracking hell when regex fails match.

get rid of unnecessary second *, or better use \.pdf$ regex.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -