2024-11-19《学习定位点与限定符》

定位点

image-20221014161720248

分组构造

image-20221014161741970

限定符

image-20221014161759146

反向引用构造

image-20221014161821470

备用构造

image-20221014161836941

替换

image-20221014161851926

杂项构造

image-20221014161911024

Regex类

image-20221014161926139

  示例:

  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();
  }
  }
  }
posted @ 2024-12-29 14:38  new菜鸟  阅读(5)  评论(0)    收藏  举报