Mega Code Archive

 
Categories / C# Tutorial / Regular Expression
 

Match words that contain u

using System; using System.Text.RegularExpressions; class MainClass {   private static void DisplayMatches(string text,string regularExpressionString) {     Console.WriteLine("using the following regular expression: " +regularExpressionString);     MatchCollection myMatchCollection = Regex.Matches(text, regularExpressionString);     foreach (Match myMatch in myMatchCollection) {       Console.WriteLine(myMatch);     }   }   public static void Main() {     string text ="put public private she";          Console.WriteLine("Matching words that contain 'u'");     DisplayMatches(text, @"\S*u+\S*");   } } Matching words that contain 'u' using the following regular expression: \S*u+\S* put public