matches words that start with 'm' and ends with 'e' - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

matches words that start with 'm' and ends with 'e'

Demo Code

using System;// w w w.j a  v  a  2  s  . c  o  m
using System.Text.RegularExpressions;
class Program {
   private static void showMatch(string text, string expr) {
      Console.WriteLine("The Expression: " + expr);
      MatchCollection mc = Regex.Matches(text, expr);
      foreach (Match m in mc) {
         Console.WriteLine(m);
      }
   }
   static void Main(string[] args) {
      string str = "Mike merge marry make maze and manage to measure it";
      Console.WriteLine("Matching words start with 'm' and ends with 'e':");
      showMatch(str, @"\bm\S*e\b");
   }
}

Result


Related Tutorials