Console.WriteLine("\n\n---\nValidate that the input is one of the 50 US States\n---"); string StatePattern = @"(:?A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])";
testMatch(StatePattern, "California"); testMatch(StatePattern, "CA"); testMatch(StatePattern, "AS"); testMatch(StatePattern, "JP"); testMatch(StatePattern, "MS"); testMatch(StatePattern, "AZ and HI");
Console.WriteLine("\n\n---\nremove HTML markup\n---"); string HTMLPattern = @"<(.|\n)*?>"; Convert(HTMLPattern, "Plain Text");
Convert(HTMLPattern, "<p>a Paragraph</p>"); Convert(HTMLPattern, "a Photo <img src=\"http://site.com/photo.jpg\" />");
Console.WriteLine("\n\n---\njpg, gif or png (or adjust to accept any kind of file.)\n---"); string ImgPattern=@"([^\s]+(?=\.(jpg|gif|png))\.\2)"; testMatch(ImgPattern, @"C:\my documents\photo.jpg"); testMatch(ImgPattern, @"Program.exe"); testMatch(ImgPattern, @"WrongKind.bmp");
Console.WriteLine("\n\n"); } } }
Console application shows some common uses of Regular Expressions (REGEX) to match and recursively replace text in strings. This console application demonstrates some common uses.