正则表达式的使用
2013-11-30 16:20
162 查看
/* 正则表达式的使用 */ using System.Text.RegularExpressions; namespace Frank { public class Test { //程序入口 public static void Main(string[] args) { const string myText = "abcdeafsgabcadefgaaabcdefagaabcdefgaa"; string pattern = "a"; MatchCollection myMatches = Regex.Matches(myText,pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture); foreach(Match item in myMatches) { System.Console.WriteLine(item.Index);//输出包含指定字符的位置索引 } System.Console.WriteLine("---------------------------------"); //查找以a开头以fg结尾,中是非空格的字符 的字符串 pattern = @"\ba\S*aa\b"; myMatches = Regex.Matches(myText,pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture); System.Console.WriteLine(myMatches[0].Success+"----"+myMatches.Count);//是否匹配成功 } } }
相关文章推荐
- 正则表达式匹配使用
- 正则表达式的使用
- C#使用正则表达式实现首字母转大写的方法
- 老男孩教育每日一题-第89天-根据如下描述使用正则表达式取出内容
- MYSQL使用正则表达式过滤数据
- Java使用正则表达式判断字符串是否以字符开始
- 正则表达式的使用
- 正则表达式使用详解
- java使用正则表达式方法和正则表达式大全
- 正则表达式的使用语法
- 正则表达式简介及在C++11中的简单使用
- java使用正则表达式方法和正则表达式大全
- Python3 如何优雅地使用正则表达式(详解四)
- 在UltraEdit中使用正则表达式
- 如何使用正则表达式搜索
- 正则表达式在IOS中的应用及IOS中三种正则表达式的使用与比较
- 使用正则表达式可以用来规范输入
- 正则表达式使用总结
- JAVA使用正则表达式Demo
- 正则表达式使用