• Regex实例


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    
    namespace RegexTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                string msg = "Welcome to China come comecome";
    
                var matchs = Regex.Matches(msg, @"come");
                foreach (var item in matchs)
                {
                    Console.WriteLine(item);
                }
    
                msg = Regex.Replace(msg,@"come","****");
                Console.WriteLine(msg);
    
    
                string content = "Welcome to 'China' 'zoro' 'zore' 'zero'";
    
                content = Regex.Replace(content, @"'(w+)'","[$1]");
    
                Console.WriteLine(content);
    
                string str = "我的生日是05/21/2010";
    
                str = Regex.Replace(str, @"(d+)/(d+)/(d+)", "$3-$2-$1");
    
                Console.WriteLine(str);
                Console.WriteLine("====================");
    
                string str2 = "zxsssssh@itcast.cn";
    
                string s = Regex.Match(str2,@"(.+)@").Groups[1].Value;
                Console.WriteLine(s);
                string left = string.Empty;
                for (int i = 0; i < s.Length; i++)
                {
                    left += "*";
                }
    
                string ss = Regex.Replace(str2, @"(.+)@", left+"@");
                Console.WriteLine(ss);
    
                Console.WriteLine("------------连线去重-----------");
    
    
                string str3 = "佐佐罗罗";
                str3 = Regex.Replace(str3, @"(.)1+", "$1");
                Console.WriteLine(str3);
    
    
                Console.WriteLine("------------查找出XXYY模式的叠词-----------");
    
    
                string str4 = "浩浩荡荡、清清白白、AABB2、如火如荼、愈演愈烈、AXAY、MNYX,ABCD、没事找事、心服口服、AABBCC";
                //查找出XXYY模式的叠词
                MatchCollection matchs4 = Regex.Matches(str4, @"(.)1(.)2");
                foreach (Match item in matchs4)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine(matchs4.Count);
    
                Console.WriteLine("------------查找出XAXB模式的叠词-----------");
    
                //查找出XAXB模式的叠词
                MatchCollection matchs5 = Regex.Matches(str4, @"(.).1.");
                foreach (Match item in matchs5)
                {
                    Console.WriteLine(item);
                }
    
                Console.WriteLine("------------查找出ABCB模式的叠词-----------");
    
                //查找出XAXB模式的叠词
                MatchCollection matchs6 = Regex.Matches(str4, @".(.).1");
                foreach (Match item in matchs6)
                {
                    Console.WriteLine(item);
                }
    
                Console.WriteLine("------------查找出ABABAB模式的叠词-----------");
    
                //查找出XAXB模式的叠词
                MatchCollection matchs7 = Regex.Matches(str4, @"(.)1(.)2(.)3");
                foreach (Match item in matchs7)
                {
                    Console.WriteLine(item);
                }
    
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    数据库分表之Mybatis+Mysql实践
    mysql中You can't specify target table for update in FROM clause错误
    SQL中的limit用法
    在电脑端打开apk文件
    mysql进阶(五)数据表中带OR的多条件查询
    Java之——汉字转换拼音(大小写)
    数据库查询模糊匹配
    produces在@requestMapping中的使用方式和作用
    JSONP跨域请求数据报错 “Unexpected token :”的解决办法
    C# TcpClient的Connect超时处理(Timeout)
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/4105270.html
Copyright © 2020-2023  润新知