当前位置:
文档之家› C#之正则表达式使用实例讲解
C#之正则表达式使用实例讲解
MatchCollection Matchs = Regex.Matches( Text , Pattern , RegexOptions.IgnoreCase );
foreach (Match i in Matchs) {
Console.WriteLine( i.Value ); }
//例:我们要查看我们的单词是不是以N开头 string myText = "Naladdin";
This comprehensive compendium provides a boroad and thor This comprehensive compendium provides a boroad and thor This comprehensive compendium provides a boroad and thor This comprehensive compendium provides a boroad and thor"; string Pattern = "thor";
2010-11-20 10:46:40
C#之正则表达式使用实例讲解Fra bibliotek我来说两句
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions;
收藏
我要投稿
namespace 字符串 {
class 正则表达式 {
public static void Main() {
//正则表达式是用来简化字符串操作的,一般正则所实现的功能,用方法也一样可以,只 是方法有可能就会变的很复杂!
//假定我们要在字符串中做一次纯文件的搜索,不用任何的正则串。 string Text = @"This comprehensive compendium provides a boroad and thor
Match mat = Regex.Match( myText , @"n" , RegexOptions.IgnoreCase ); Console.WriteLine(myText "是否以N开头" mat.Success);
//以A开头,以ion结尾 string myText2 = "Applaldafaslkdfasd;fasdfasdfasdfadsfadfadsfication"; Match mat2 = Regex.Match(myText2, @"aS*ion", RegexOptions.IgnoreCase); Console.WriteLine(myText2 "是否以A开头Ion结尾,任意长度的单词" mat2.Success);
Console.ReadLine();
} } }