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, @"\bcome\b");
foreach (var item in matchs)
{
Console.WriteLine(item);
} msg = Regex.Replace(msg,@"\bcome\b","****");
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[].Value;
Console.WriteLine(s);
string left = string.Empty;
for (int i = ; 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();
}
}
}

最新文章

  1. HTML&CSS日常知识点总结
  2. Delphi 各版本新特性功能网址收集
  3. shell return value
  4. MVC3 Model Binding验证方式
  5. 常见的HTTP状态码深入理解
  6. mongoDB之用户及权限设置
  7. 演练5-8:Contoso大学校园管理系统(实现存储池和工作单元模式)
  8. Vue跨门槛系列之实例的阐述
  9. NodeJs学习笔记(四)---单元测试
  10. 【数据库】数据库的锁机制,MySQL中的行级锁,表级锁,页级锁
  11. C# - 设计模式 - 虚模式
  12. blob canvas img dataUrl的互相转换和用处
  13. Vi编辑器中全局替换
  14. 杂谈c.cpp
  15. FTP实验
  16. spring4.0之三:@RestController
  17. WebStorm新创建项目介绍
  18. Qt5.3.2_CentOS6.4_单步调试环境__20160306【勿删,繁琐】
  19. VBA 公式中使用相对位置
  20. jquery正则判断字符串有几个逗号

热门文章

  1. linux ubuntu nethogs安装与介绍
  2. 黄金Corner
  3. BZOJ3724 PA2014Final Krolestwo(欧拉回路+构造)
  4. startSSL 申请免费的SSL证书
  5. [luogu2522][bzoj2301][HAOI2011]Problem b【莫比乌斯反演】
  6. C代码快速构建框架
  7. VirtualBox中slitaz系统不能联网
  8. (转)sublime text3简体中文版汉化教程
  9. 搞定 Kubernetes 基于flannel 的集群网络
  10. pyglet--旋转的矩形