matches words that start with 'S' - CSharp Language Basics

CSharp examples for Language Basics:Regex

Description

matches words that start with 'S'

Demo Code

using System;//from  ww  w . j  ava  2s . com
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 = "Seven Sad Test Thousand Splendid Suns";
         showMatch(str, @"\bS\S*");
      }
}

Result


Related Tutorials