Ade sends some code that he discovered as the culprit behind some searches taking, literally, forever to complete. Written by a senior developer at his company, I believe we can officially nominate this as the “Regular Expre-What?” Function of the Year. It's quite impressive to see nine potential endless loops in such a small function, although this still remains proof positive that (9*INFINITY) is still infinity.

private static string StripAllSearchCharacters(string Criteria)
{
 int iPos = -1;

 iPos = Criteria.IndexOf("*");      
 while (iPos != -1)
 {
  //ED: String.Remove() returns a string; it does not change the string itself
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("*");    
 }

 iPos = Criteria.IndexOf("<");      
 while (iPos != -1)
 {
   Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("<");    
 }

 iPos = Criteria.IndexOf(">");      
 while (iPos != -1)
 {
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf(">");    
 }

 iPos = Criteria.IndexOf("!");      
 while (iPos != -1)
 {
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("!");    
 }


 iPos = Criteria.IndexOf("&");      
 while (iPos != -1)
 {
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("&");    
 }  

 iPos = Criteria.IndexOf("|");      
 while (iPos != -1)
 {
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("|");    
 }

 iPos = Criteria.IndexOf("?");      
 while (iPos != -1)
 {
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("?");    
 }

 iPos = Criteria.IndexOf("!=");      
 while (iPos != -1)
 {
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("!=");    
 }

 iPos = Criteria.IndexOf("=");      
 while (iPos != -1)
 {
  Criteria.Remove(iPos, 1);
  iPos = Criteria.IndexOf("=");    
 }

 return Criteria;
}

Speaking of the Function of the Year, Raymond Chen nominated one as well. And, coming soon, just in time for Halloween, the scarriest system of the year ...

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!