C#正则表达式

匹配了以 'S' 开头的单词:

using System;
using System.Text.RegularExpressions;

namespace RegExApplication
{
   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 = "A Thousand Splendid Suns";

         Console.WriteLine("Matching words that start with 'S': ");
         showMatch(str, @"\bS\S*");
         Console.ReadKey();
      }
   }
}

结果:

Matching words that start with 'S':
The Expression: \bS\S*
Splendid
Suns

 

posted @ 2017-01-18 10:34  .追风逐月  阅读(168)  评论(0编辑  收藏  举报