C#中使用正则表达式匹配字符串的方法如下:
1.使用System.Text.RegularExpressions命名空间;
2.使用Matches()方法匹配字符串,格式如下:
MatchCollection Matches = Regex.Matches(Str, Pattern, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
其中Str表示输入字符串,Pattern表示匹配模式,RegexOptions.IgnoreCase表示忽略大小写,RegexOptions.ExplicitCapture表示改变收集匹配方式。
3.匹配结果保存在MatchCollection集合中,可以通过循环遍历结果集取出Match对象的结果。

TestRagular.cs:
 
01.using System; 
02.using System.Text.RegularExpressions; 
03.  
04.namespace Magci.Test.Strings 
05.{