zoukankan      html  css  js  c++  java
  • C#正则分组实例

     static void Main(string[] args)
            {
                string str = "大家家家家家家家明天天天天天天天天玩得得得得得得得开心";
                Regex reg = new Regex(@"(?<wdq>.)<wdq>{2,}");
                var ms = reg.Matches(str);
                Console.WriteLine("一共" + ms.Count + "");
                foreach (Match item in ms)
                {
                    Console.WriteLine(item.Groups["wdq"]);
                    Console.WriteLine(item.Value);
                    Console.WriteLine("------------------");
                }
                Console.ReadKey();
            }
     static void Main(string[] args)
            {
                string str = "大家家家家家家家明天天天天天天天天玩得得得得得得得开心";
                Regex reg = new Regex(@"(?<wdq>.)1{2,}");
                var ms = reg.Matches(str);
                Console.WriteLine("一共" + ms.Count + "");
                foreach (Match item in ms)
                {
                    Console.WriteLine(item.Groups["wdq"]);
                    Console.WriteLine(item.Value);
                    Console.WriteLine("------------------");
                }
                Console.ReadKey();
            }

    这是两组代码,前面一组演示分组命名以及命名的分组的使用。

    后一组演示的是,使用序号标识分组

  • 相关阅读:
    js history对象 手机物理返回键
    正则表达式学习整理
    js获得时间new Date()整理
    币值转换
    打印沙漏
    秋季总结
    对我影响最大的三位老师
    我就是我
    秋季学期学习总结
    自我介绍
  • 原文地址:https://www.cnblogs.com/a14907/p/5184392.html
Copyright © 2011-2022 走看看