string i = @"Live for nothing,
die for something";//多行
        Regex r3 = new Regex("^Live for nothing,\r\ndie for something$");
        Console.WriteLine("r3 match count:" + r3.Matches(i).Count);//1
        Regex r8 = new Regex("^Live for nothing,\r$");
        Console.WriteLine("r8 match count:" + r8.Matches(i).Count);//0
        Regex r9 = new Regex("^Live for nothing,\r$", RegexOptions.Multiline);
        Console.WriteLine("r9 match count:" + r9.Matches(i).Count);//1
       //对于一个多行字符串,在设置了Multiline选项之后,^和$将出现多次匹配。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2021-10-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-07-23
  • 2021-08-18
  • 2021-08-06
  • 2022-12-23
相关资源
相似解决方案