高分求正则表达式的资料! 看msdn吧。。资料很全。。我是记不住具体的用法了。。或者是本网站的技术专栏里。。有文章。。不错的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System.Text.RegularExpressions; string Text="The software ad,is MeTone, a,is very gaaad!,Your Need"; //一般// string Pattern="is";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,以n开头的单词// string Pattern=@"\bn";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,以e结尾的单词// string Pattern=@"e\b";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,以M开头,以e结尾,中间是任何数量不为空的字符,\S表示不是空白的字符,*任何数量// string Pattern=@"\bM\S*e\b";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,以T只能是总文本中的第一个字符// string Pattern=@"^T";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,以d只能是总文本中的第一个字符// string Pattern=@"d$";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,.是除以换行符\n以外的任何一个字符// string Pattern=@"g.d";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); // Console.WriteLine(NextMatch.Index); //转义,+可以重复一次或多次的前导字符// string Pattern=@"ga+d";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,?可以重复零次或多次的前导字符// string Pattern=@"ga+d";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //转义,?可以重复零次或多次的前导字符// string Pattern=@"\sa";// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);// foreach(Match NextMatch in Matches)// Console.WriteLine(NextMatch.Index); //提取网址 Text="I'found the URL is http://www.emay.net.cn is very good"; string Pattern=@"\b(\S+)://(\S+)(?::(\S+))?\b"; MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture); foreach(Match NextMatch in Matches) Console.WriteLine(NextMatch); 给你个地址,这里面很多正则表达式的例子!http://www.regexplib.com/DisplayPatterns.aspx c#读取远程服务器上的文件并生成一棵树 字符串替换问题求解 Remoting架构下远程连接数据库出现的问题 ARRAYLIST 相加的问题 如何判断一个文件是否为EXCEL? 如何判断一个字符串是另一数组的子序列 visual studio 调用哪个命令行工具。 把xml生成xsd文件 宝信!急 !在线等!! 急,大侠们来解决SmartClient生成升级清单的小错误 smart client 请问大家做论坛都有什么数据库 javascript问题
string Text="The software ad,is MeTone, a,is very gaaad!,Your Need";
//一般
// string Pattern="is";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,以n开头的单词
// string Pattern=@"\bn";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,以e结尾的单词
// string Pattern=@"e\b";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,以M开头,以e结尾,中间是任何数量不为空的字符,\S表示不是空白的字符,*任何数量
// string Pattern=@"\bM\S*e\b";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,以T只能是总文本中的第一个字符
// string Pattern=@"^T";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,以d只能是总文本中的第一个字符
// string Pattern=@"d$";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,.是除以换行符\n以外的任何一个字符
// string Pattern=@"g.d";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
// Console.WriteLine(NextMatch.Index);
//转义,+可以重复一次或多次的前导字符
// string Pattern=@"ga+d";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,?可以重复零次或多次的前导字符
// string Pattern=@"ga+d";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//转义,?可以重复零次或多次的前导字符
// string Pattern=@"\sa";
// MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
// foreach(Match NextMatch in Matches)
// Console.WriteLine(NextMatch.Index);
//提取网址
Text="I'found the URL is http://www.emay.net.cn is very good";
string Pattern=@"\b(\S+)://(\S+)(?::(\S+))?\b";
MatchCollection Matches=Regex.Matches(Text,Pattern,RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture);
foreach(Match NextMatch in Matches)
Console.WriteLine(NextMatch);